From a1bbe0c7f247b5919e21414f3863df39631ff53c Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 25 Jun 2018 22:50:57 -0400 Subject: [PATCH] review fix --- gencapdefs.py | 8 ++------ irc/caps/constants.go | 6 ++++++ irc/caps/defs.go | 8 ++------ irc/responsebuffer.go | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gencapdefs.py b/gencapdefs.py index f828a38d..4f2d76c6 100644 --- a/gencapdefs.py +++ b/gencapdefs.py @@ -15,12 +15,6 @@ from collections import namedtuple 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", @@ -188,11 +182,13 @@ const ( 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: diff --git a/irc/caps/constants.go b/irc/caps/constants.go index d618bd08..84424702 100644 --- a/irc/caps/constants.go +++ b/irc/caps/constants.go @@ -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 { diff --git a/irc/caps/defs.go b/irc/caps/defs.go index 7fb5d578..492065c6 100644 --- a/irc/caps/defs.go +++ b/irc/caps/defs.go @@ -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 @@ -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", diff --git a/irc/responsebuffer.go b/irc/responsebuffer.go index 7ab697ec..a1071e53 100644 --- a/irc/responsebuffer.go +++ b/irc/responsebuffer.go @@ -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. @@ -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