diff options
author | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-16 17:02:22 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-16 17:17:29 +0200 |
commit | f1791d1c6e7fc3ac4d27bb206b1bd61d80fe96f0 (patch) | |
tree | bb325625135245ccbef9018577d50ad08e52828c /irc/states.go | |
parent | ui: Show /me from self when echo-message is off (diff) |
Add a /topic command
Diffstat (limited to '')
-rw-r--r-- | irc/states.go | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/irc/states.go b/irc/states.go index 1405c48..aba6536 100644 --- a/irc/states.go +++ b/irc/states.go @@ -80,6 +80,10 @@ type ( actionPart struct { Channel string } + actionSetTopic struct { + Channel string + Topic string + } actionPrivMsg struct { Target string @@ -113,6 +117,10 @@ type Channel struct { Secret bool } +func (c *Channel) SetTopic(topic string) { + c.Topic = topic +} + type SessionParams struct { Nickname string Username string @@ -240,6 +248,15 @@ func (s *Session) IsChannel(name string) bool { return strings.IndexAny(name, "#&") == 0 // TODO compute CHANTYPES } +func (s *Session) Topic(channel string) string { + channelCf := strings.ToLower(channel) + if c, ok := s.channels[channelCf]; ok { + return c.Topic + } else { + return "" + } +} + func (s *Session) SendRaw(raw string) { s.acts <- actionSendRaw{raw} } @@ -267,6 +284,15 @@ func (s *Session) part(act actionPart) (err error) { return } +func (s *Session) SetTopic(channel, topic string) { + s.acts <- actionSetTopic{channel, topic} +} + +func (s *Session) setTopic(act actionSetTopic) (err error) { + err = s.send("TOPIC %s %s\r\n", act.Channel, act.Topic) + return +} + func (s *Session) PrivMsg(target, content string) { s.acts <- actionPrivMsg{target, content} } @@ -339,6 +365,8 @@ func (s *Session) run() { err = s.join(act) case actionPart: err = s.part(act) + case actionSetTopic: + err = s.setTopic(act) case actionPrivMsg: err = s.privMsg(act) case actionTyping: @@ -665,9 +693,21 @@ func (s *Session) handle(msg Message) (err error) { } case rplTopic: channelCf := strings.ToLower(msg.Params[1]) - if c, ok := s.channels[channelCf]; ok { c.Topic = msg.Params[2] + s.channels[channelCf] = c + } + case rplNotopic: + channelCf := strings.ToLower(msg.Params[1]) + if c, ok := s.channels[channelCf]; ok { + c.Topic = "" + s.channels[channelCf] = c + } + case "TOPIC": + channelCf := strings.ToLower(msg.Params[0]) + if c, ok := s.channels[channelCf]; ok { + c.Topic = msg.Params[1] + s.channels[channelCf] = c } case "PRIVMSG", "NOTICE": s.evts <- s.privmsgToEvent(msg) |