From bded3202c214d157bd3e98502f9b4422c191336a Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 26 Jun 2016 21:06:28 +1000 Subject: [PATCH] channels: send RPL_CHANNELCREATED and RPL_TOPICTIME --- irc/channel.go | 28 ++++++++++++++++++---------- irc/modes.go | 2 ++ irc/numerics.go | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 34b6cc45..c64caf8f 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -8,18 +8,22 @@ package irc import ( "log" "strconv" + "time" ) type Channel struct { - flags ChannelModeSet - lists map[ChannelMode]*UserMaskSet - key string - members MemberSet - name Name - nameString string - server *Server - topic string - userLimit uint64 + flags ChannelModeSet + lists map[ChannelMode]*UserMaskSet + key string + members MemberSet + name Name + nameString string + server *Server + createdTime time.Time + topic string + topicSetBy string + topicSetTime time.Time + userLimit uint64 } // NewChannel creates a new channel from a `Server` and a `name` @@ -205,6 +209,7 @@ func (channel *Channel) Join(client *Client, key string) { client.channels.Add(channel) channel.members.Add(client) if !channel.flags[Persistent] && (len(channel.members) == 1) { + channel.createdTime = time.Now() channel.members[client][ChannelFounder] = true channel.members[client][ChannelOperator] = true } @@ -238,7 +243,7 @@ func (channel *Channel) GetTopic(client *Client) { } client.Send(nil, client.server.nameString, RPL_TOPIC, client.nickString, channel.nameString, channel.topic) - //TODO(dan): show topic time and setter here too + client.Send(nil, client.server.nameString, RPL_TOPICTIME, client.nickString, channel.nameString, channel.topicSetBy, strconv.FormatInt(channel.topicSetTime.Unix(), 10)) } func (channel *Channel) SetTopic(client *Client, topic string) { @@ -253,6 +258,8 @@ func (channel *Channel) SetTopic(client *Client, topic string) { } channel.topic = topic + channel.topicSetBy = client.nickString + channel.topicSetTime = time.Now() for member := range channel.members { member.Send(nil, client.nickMaskString, "TOPIC", channel.nameString, channel.topic) @@ -404,6 +411,7 @@ func (channel *Channel) applyModeMask(client *Client, mode ChannelMode, op ModeO func (channel *Channel) Persist() (err error) { if channel.flags[Persistent] { + //TODO(dan): Save topicSetBy/topicSetTime and createdTime _, err = channel.server.db.Exec(` INSERT OR REPLACE INTO channel (name, flags, key, topic, user_limit, ban_list, except_list, diff --git a/irc/modes.go b/irc/modes.go index 16982a67..ebf23d45 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -6,6 +6,7 @@ package irc import ( + "strconv" "strings" "github.com/DanielOaks/girc-go/ircmsg" @@ -371,6 +372,7 @@ func cmodeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { //TODO(dan): we should just make ModeString return a slice here args := append([]string{client.nickString, channel.nameString}, strings.Split(channel.ModeString(client), " ")...) client.Send(nil, client.nickMaskString, RPL_CHANNELMODEIS, args...) + client.Send(nil, client.nickMaskString, RPL_CHANNELCREATED, client.nickString, channel.nameString, strconv.FormatInt(channel.createdTime.Unix(), 10)) } return false } diff --git a/irc/numerics.go b/irc/numerics.go index b92219a6..934216c0 100644 --- a/irc/numerics.go +++ b/irc/numerics.go @@ -60,9 +60,10 @@ const ( RPL_LISTEND = "323" RPL_CHANNELMODEIS = "324" RPL_UNIQOPIS = "325" - RPL_CREATIONTIME = "329" + RPL_CHANNELCREATED = "329" RPL_NOTOPIC = "331" RPL_TOPIC = "332" + RPL_TOPICTIME = "333" RPL_INVITING = "341" RPL_SUMMONING = "342" RPL_INVITELIST = "346"