From e1c235a9ea89742cd66b7d49f362d66dcb150de7 Mon Sep 17 00:00:00 2001 From: Edmund Huber Date: Sat, 22 Mar 2014 22:15:52 +0100 Subject: [PATCH 1/2] fix up MODE behavior to allow /mode and show per-channel modes, fixes #29 --- irc/modes.go | 6 ++++-- irc/reply.go | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/irc/modes.go b/irc/modes.go index 717e9c32..040f63de 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -145,10 +145,12 @@ func (m *ModeCommand) HandleServer(s *Server) { } } - // Who should get these replies? if len(changes) > 0 { - client.Reply(RplMode(client, target, changes)) + client.Reply(RplModeChanges(client, target, changes)) + } else if client == target { + client.RplUModeIs(client) } + client.Reply(RplCurrentMode(client, target)) } func (msg *ChannelModeCommand) HandleServer(server *Server) { diff --git a/irc/reply.go b/irc/reply.go index b4304bfb..5f5ad27d 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -119,10 +119,25 @@ func RplPart(client *Client, channel *Channel, message Text) string { return NewStringReply(client, PART, "%s :%s", channel, message) } -func RplMode(client *Client, target *Client, changes ModeChanges) string { +func RplModeChanges(client *Client, target *Client, changes ModeChanges) string { return NewStringReply(client, MODE, "%s :%s", target.Nick(), changes) } +func RplCurrentMode(client *Client, target *Client) string { + globalFlags := "" + for mode, _ := range target.flags { + globalFlags += mode.String() + } + + perChannelFlags := "" + for channel, _ := range target.channels { + perChannelFlags += fmt.Sprintf(" %s:%s", channel.name, channel.members[target]) + } + + response := fmt.Sprintf("All user modes: %s%s", globalFlags, perChannelFlags) + return NewStringReply(client, NOTICE, "%s :%s", target.Nick(), response) +} + func RplChannelMode(client *Client, channel *Channel, changes ChannelModeChanges) string { return NewStringReply(client, MODE, "%s %s", channel, changes) From b4edcea6e342074751a6dcf32ac5579ebe8cb154 Mon Sep 17 00:00:00 2001 From: Edmund Huber Date: Sat, 29 Mar 2014 19:46:44 +0100 Subject: [PATCH 2/2] pretty up the notice a bit, and use RplNotice --- irc/reply.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/irc/reply.go b/irc/reply.go index 5f5ad27d..bf2beac2 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -124,7 +124,7 @@ func RplModeChanges(client *Client, target *Client, changes ModeChanges) string } func RplCurrentMode(client *Client, target *Client) string { - globalFlags := "" + globalFlags := "global:" for mode, _ := range target.flags { globalFlags += mode.String() } @@ -134,8 +134,8 @@ func RplCurrentMode(client *Client, target *Client) string { perChannelFlags += fmt.Sprintf(" %s:%s", channel.name, channel.members[target]) } - response := fmt.Sprintf("All user modes: %s%s", globalFlags, perChannelFlags) - return NewStringReply(client, NOTICE, "%s :%s", target.Nick(), response) + response := NewText(fmt.Sprintf("user %s has %s%s", target.nick, globalFlags, perChannelFlags)) + return RplNotice(client.server, client, response) } func RplChannelMode(client *Client, channel *Channel,