From f24bb5ee7dee45d745747c5c93d9f9eafc0bbefa Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Sun, 12 May 2013 11:37:35 -0700 Subject: [PATCH] Make channel and privmsg replies more useful for logged-out users. --- src/irc/channel.go | 4 ++-- src/irc/commands.go | 8 ++++++++ src/irc/server.go | 20 +++++++++----------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/irc/channel.go b/src/irc/channel.go index 570a5413..3ba213fd 100644 --- a/src/irc/channel.go +++ b/src/irc/channel.go @@ -158,7 +158,7 @@ func (m *PartCommand) HandleChannel(channel *Channel) { } func (m *TopicCommand) HandleChannel(channel *Channel) { - user := m.Client().user + user := m.User() if !channel.members[user] { user.replies <- ErrNotOnChannel(channel) @@ -181,5 +181,5 @@ func (m *TopicCommand) HandleChannel(channel *Channel) { } func (m *PrivMsgCommand) HandleChannel(channel *Channel) { - channel.Replies() <- RplPrivMsgChannel(channel, m.Client().user, m.message) + channel.Replies() <- RplPrivMsgChannel(channel, m.User(), m.message) } diff --git a/src/irc/commands.go b/src/irc/commands.go index 32dfee52..f6499cea 100644 --- a/src/irc/commands.go +++ b/src/irc/commands.go @@ -9,6 +9,7 @@ import ( type Command interface { Client() *Client + User() *User Source() Identifier HandleServer(*Server) } @@ -44,6 +45,13 @@ func (command *BaseCommand) Client() *Client { return command.client } +func (command *BaseCommand) User() *User { + if command.Client() == nil { + return nil + } + return command.User() +} + func (command *BaseCommand) SetClient(c *Client) { command.client = c } diff --git a/src/irc/server.go b/src/irc/server.go index e76a3988..b9ccfa12 100644 --- a/src/irc/server.go +++ b/src/irc/server.go @@ -228,9 +228,7 @@ func (m *JoinCommand) HandleServer(s *Server) { c := m.Client() if c.user == nil { - for name := range m.channels { - c.Replies() <- ErrNoSuchChannel(s, name) - } + c.Replies() <- ErrNoPrivileges(s) return } @@ -250,12 +248,10 @@ func (m *JoinCommand) HandleServer(s *Server) { } func (m *PartCommand) HandleServer(s *Server) { - user := m.Client().user + user := m.User() if user == nil { - for _, chname := range m.channels { - m.Client().Replies() <- ErrNoSuchChannel(s, chname) - } + m.Client().Replies() <- ErrNoPrivileges(s) return } @@ -272,10 +268,11 @@ func (m *PartCommand) HandleServer(s *Server) { } func (m *TopicCommand) HandleServer(s *Server) { - user := m.Client().user + user := m.User() + // Hide all channels from logged-out clients. if user == nil { - m.Client().Replies() <- ErrNoSuchChannel(s, m.channel) + m.Client().Replies() <- ErrNoPrivileges(s) return } @@ -295,9 +292,10 @@ func (m *PrivMsgCommand) HandleServer(s *Server) { return } - user := m.Client().user + user := m.User() + // Hide all users from logged-out clients. if user == nil { - m.Client().Replies() <- ErrNoSuchNick(s, m.target) + m.Client().Replies() <- ErrNoPrivileges(s) return }