Request server-time cap

If the server didn't populate the time tag, do it ourselves.
This commit is contained in:
Simon Ser 2020-03-31 19:45:04 +02:00
parent 29a42203b6
commit 2053e62162
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 12 additions and 1 deletions

3
irc.go
View File

@ -201,3 +201,6 @@ type batch struct {
Outer *batch // if not-nil, this batch is nested in Outer
Label string
}
// The server-time layout, as defined in the IRCv3 spec.
const serverTimeLayout = "2006-01-02T15:04:05.000Z"

View File

@ -365,7 +365,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
}
requestCaps := make([]string, 0, 16)
for _, c := range []string{"message-tags", "batch", "labeled-response"} {
for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time"} {
if _, ok := uc.caps[c]; ok {
requestCaps = append(requestCaps, c)
}
@ -1207,6 +1207,10 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
break
}
if _, ok := msg.Tags["time"]; !ok {
msg.Tags["time"] = irc.TagValue(time.Now().Format(serverTimeLayout))
}
target := nick
if nick == uc.nick {
target = msg.Prefix.Name
@ -1373,6 +1377,10 @@ func (uc *upstreamConn) handleCapAck(name string, ok bool) error {
uc.tagsSupported = ok
case "labeled-response":
uc.labelsSupported = ok
case "batch", "server-time":
// Nothing to do
default:
uc.logger.Printf("received CAP ACK/NAK for a cap we don't support: %v", name)
}
return nil
}