upstream: don't populate time tag for numerics

Allows us to save a few bytes, e.g. in WHO replies.
This commit is contained in:
Simon Ser 2022-03-22 21:14:02 +01:00
parent 09513e63fe
commit 16e43ee3a3
2 changed files with 13 additions and 1 deletions

12
irc.go
View File

@ -848,3 +848,15 @@ func (cr *capRegistry) SetEnabled(name string, enabled bool) {
delete(cr.Enabled, name) delete(cr.Enabled, name)
} }
} }
func isNumeric(cmd string) bool {
if len(cmd) != 3 {
return false
}
for i := 0; i < 3; i++ {
if cmd[i] < '0' || cmd[i] > '9' {
return false
}
}
return true
}

View File

@ -450,7 +450,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
msg.Prefix = uc.serverPrefix msg.Prefix = uc.serverPrefix
} }
if _, ok := msg.Tags["time"]; !ok { if _, ok := msg.Tags["time"]; !ok && !isNumeric(msg.Command) {
msg.Tags["time"] = irc.TagValue(formatServerTime(time.Now())) msg.Tags["time"] = irc.TagValue(formatServerTime(time.Now()))
} }