Add support for account-tag

This commit is contained in:
Simon Ser 2021-06-14 21:44:38 +02:00
parent cacbd48949
commit b609b86f97
2 changed files with 11 additions and 3 deletions

View File

@ -131,6 +131,7 @@ var permanentDownstreamCaps = map[string]string{
// needAllDownstreamCaps is the list of downstream capabilities that
// require support from all upstreams to be enabled
var needAllDownstreamCaps = map[string]string{
"account-tag": "",
"away-notify": "",
"extended-join": "",
"multi-prefix": "",
@ -375,6 +376,8 @@ func (dc *downstreamConn) SendMessage(msg *irc.Message) {
switch name {
case "time":
supported = dc.caps["server-time"]
case "account":
supported = dc.caps["account"]
}
if !supported {
delete(msg.Tags, name)
@ -1950,6 +1953,9 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
echoTags := tags.Copy()
echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
if uc.account != "" {
echoTags["account"] = irc.TagValue(uc.account)
}
echoMsg := &irc.Message{
Tags: echoTags,
Prefix: &irc.Prefix{

View File

@ -21,6 +21,7 @@ import (
// permanentUpstreamCaps is the static list of upstream capabilities always
// requested when supported.
var permanentUpstreamCaps = map[string]bool{
"account-tag": true,
"away-notify": true,
"batch": true,
"extended-join": true,
@ -94,6 +95,7 @@ type upstreamConn struct {
caps map[string]bool
batches map[string]batch
away bool
account string
nextLabelID uint64
saslClient sasl.Client
@ -534,12 +536,12 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
Params: []string{respStr},
})
case irc.RPL_LOGGEDIN:
var account string
if err := parseMessageParams(msg, nil, nil, &account); err != nil {
if err := parseMessageParams(msg, nil, nil, &uc.account); err != nil {
return err
}
uc.logger.Printf("logged in with account %q", account)
uc.logger.Printf("logged in with account %q", uc.account)
case irc.RPL_LOGGEDOUT:
uc.account = ""
uc.logger.Printf("logged out")
case irc.ERR_NICKLOCKED, irc.RPL_SASLSUCCESS, irc.ERR_SASLFAIL, irc.ERR_SASLTOOLONG, irc.ERR_SASLABORTED:
var info string