diff options
author | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-16 21:26:11 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-16 21:26:11 +0200 |
commit | e7efe87034d68f079ed3e8ed5a7d8f32da4cd4d4 (patch) | |
tree | bd144e9ad3c06f79885685df1714d40e3d6c24e4 /irc | |
parent | ui: Configurable nick column width (diff) |
Handle RPL_TOPICWHOTIME
Diffstat (limited to 'irc')
-rw-r--r-- | irc/states.go | 18 | ||||
-rw-r--r-- | irc/tokens.go | 11 |
2 files changed, 25 insertions, 4 deletions
diff --git a/irc/states.go b/irc/states.go index aba6536..0896dca 100644 --- a/irc/states.go +++ b/irc/states.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "strconv" "strings" "sync/atomic" "time" @@ -248,13 +249,14 @@ func (s *Session) IsChannel(name string) bool { return strings.IndexAny(name, "#&") == 0 // TODO compute CHANTYPES } -func (s *Session) Topic(channel string) string { +func (s *Session) Topic(channel string) (topic string, who string, at time.Time) { channelCf := strings.ToLower(channel) if c, ok := s.channels[channelCf]; ok { - return c.Topic - } else { - return "" + topic = c.Topic + who = c.TopicWho + at = c.TopicTime } + return } func (s *Session) SendRaw(raw string) { @@ -697,6 +699,14 @@ func (s *Session) handle(msg Message) (err error) { c.Topic = msg.Params[2] s.channels[channelCf] = c } + case rplTopicwhotime: + channelCf := strings.ToLower(msg.Params[1]) + t, _ := strconv.ParseInt(msg.Params[3], 10, 64) + if c, ok := s.channels[channelCf]; ok { + c.TopicWho = msg.Params[2] + c.TopicTime = time.Unix(t, 0) + s.channels[channelCf] = c + } case rplNotopic: channelCf := strings.ToLower(msg.Params[1]) if c, ok := s.channels[channelCf]; ok { diff --git a/irc/tokens.go b/irc/tokens.go index eda8018..04b1d86 100644 --- a/irc/tokens.go +++ b/irc/tokens.go @@ -3,6 +3,7 @@ package irc import ( "errors" "fmt" + "strconv" "strings" "time" ) @@ -297,6 +298,16 @@ func (msg *Message) Validate() (err error) { if len(msg.Params) < 3 { err = errNotEnoughParams } + case rplTopicwhotime: + if len(msg.Params) < 4 { + err = errNotEnoughParams + } else if _, err := strconv.ParseInt(msg.Params[3], 10, 64); err != nil { + err = errIncompleteMessage + } + case rplNotopic: + if len(msg.Params) < 2 { + err = errNotEnoughParams + } case "TOPIC": if len(msg.Params) < 2 { err = errNotEnoughParams |