Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
slingamn committed Jun 26, 2018
1 parent 2a33c14 commit a1bbe0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
8 changes: 2 additions & 6 deletions gencapdefs.py
Expand Up @@ -15,12 +15,6 @@
CapDef = namedtuple("CapDef", ['identifier', 'name', 'url', 'standard'])

CAPDEFS = [
CapDef(
identifier="LabelTagName",
name="draft/label",
url="https://ircv3.net/specs/extensions/labeled-response.html",
standard="draft IRCv3 tag name",
),
CapDef(
identifier="AccountNotify",
name="account-notify",
Expand Down Expand Up @@ -188,11 +182,13 @@ def main():
print(file=output)
print(")", file=output)

print("// `capabilityNames[capab]` is the string name of the capability `capab`", file=output)
print("""var ( capabilityNames = [numCapabs]string{""", file=output)
for capdef in CAPDEFS:
print("\"%s\"," % (capdef.name,), file=output)
print("})", file=output)

# run the generated code through `gofmt -s`, which will print it to stdout
gofmt = subprocess.Popen(['gofmt', '-s'], stdin=subprocess.PIPE)
gofmt.communicate(input=output.getvalue().encode('utf-8'))
if gofmt.poll() != 0:
Expand Down
6 changes: 6 additions & 0 deletions irc/caps/constants.go
Expand Up @@ -51,6 +51,12 @@ const (
NegotiatedState State = iota
)

const (
// LabelTagName is the tag name used for the labeled-response spec.
// https://ircv3.net/specs/extensions/labeled-response.html
LabelTagName = "draft/label"
)

func init() {
nameToCapability = make(map[string]Capability)
for capab, name := range capabilityNames {
Expand Down
8 changes: 2 additions & 6 deletions irc/caps/defs.go
Expand Up @@ -7,16 +7,12 @@ package caps

const (
// number of recognized capabilities:
numCapabs = 21
numCapabs = 20
// length of the uint64 array that represents the bitset:
bitsetLen = 1
)

const (
// LabelTagName is the draft IRCv3 tag name capability named "draft/label":
// https://ircv3.net/specs/extensions/labeled-response.html
LabelTagName Capability = iota

// AccountNotify is the IRCv3 capability named "account-notify":
// https://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = iota
Expand Down Expand Up @@ -98,9 +94,9 @@ const (
UserhostInNames Capability = iota
)

// `capabilityNames[capab]` is the string name of the capability `capab`
var (
capabilityNames = [numCapabs]string{
"draft/label",
"account-notify",
"account-tag",
"away-notify",
Expand Down
6 changes: 3 additions & 3 deletions irc/responsebuffer.go
Expand Up @@ -23,7 +23,7 @@ type ResponseBuffer struct {

// GetLabel returns the label from the given message.
func GetLabel(msg ircmsg.IrcMessage) string {
return msg.Tags[caps.LabelTagName.Name()].Value
return msg.Tags[caps.LabelTagName].Value
}

// NewResponseBuffer returns a new ResponseBuffer.
Expand Down Expand Up @@ -90,13 +90,13 @@ func (rb *ResponseBuffer) Send() error {
// if label but no batch, add label to first message
if useLabel && batch == nil {
message := rb.messages[0]
message.Tags[caps.LabelTagName.Name()] = ircmsg.MakeTagValue(rb.Label)
message.Tags[caps.LabelTagName] = ircmsg.MakeTagValue(rb.Label)
rb.messages[0] = message
}

// start batch if required
if batch != nil {
batch.Start(rb.target, ircmsg.MakeTags(caps.LabelTagName.Name(), rb.Label))
batch.Start(rb.target, ircmsg.MakeTags(caps.LabelTagName, rb.Label))
}

// send each message out
Expand Down

0 comments on commit a1bbe0c

Please sign in to comment.