3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Make channel and privmsg replies more useful for logged-out users.

This commit is contained in:
Jeremy Latt 2013-05-12 11:37:35 -07:00
parent fd814bf969
commit f24bb5ee7d
3 changed files with 19 additions and 13 deletions

View File

@ -158,7 +158,7 @@ func (m *PartCommand) HandleChannel(channel *Channel) {
} }
func (m *TopicCommand) HandleChannel(channel *Channel) { func (m *TopicCommand) HandleChannel(channel *Channel) {
user := m.Client().user user := m.User()
if !channel.members[user] { if !channel.members[user] {
user.replies <- ErrNotOnChannel(channel) user.replies <- ErrNotOnChannel(channel)
@ -181,5 +181,5 @@ func (m *TopicCommand) HandleChannel(channel *Channel) {
} }
func (m *PrivMsgCommand) 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)
} }

View File

@ -9,6 +9,7 @@ import (
type Command interface { type Command interface {
Client() *Client Client() *Client
User() *User
Source() Identifier Source() Identifier
HandleServer(*Server) HandleServer(*Server)
} }
@ -44,6 +45,13 @@ func (command *BaseCommand) Client() *Client {
return command.client return command.client
} }
func (command *BaseCommand) User() *User {
if command.Client() == nil {
return nil
}
return command.User()
}
func (command *BaseCommand) SetClient(c *Client) { func (command *BaseCommand) SetClient(c *Client) {
command.client = c command.client = c
} }

View File

@ -228,9 +228,7 @@ func (m *JoinCommand) HandleServer(s *Server) {
c := m.Client() c := m.Client()
if c.user == nil { if c.user == nil {
for name := range m.channels { c.Replies() <- ErrNoPrivileges(s)
c.Replies() <- ErrNoSuchChannel(s, name)
}
return return
} }
@ -250,12 +248,10 @@ func (m *JoinCommand) HandleServer(s *Server) {
} }
func (m *PartCommand) HandleServer(s *Server) { func (m *PartCommand) HandleServer(s *Server) {
user := m.Client().user user := m.User()
if user == nil { if user == nil {
for _, chname := range m.channels { m.Client().Replies() <- ErrNoPrivileges(s)
m.Client().Replies() <- ErrNoSuchChannel(s, chname)
}
return return
} }
@ -272,10 +268,11 @@ func (m *PartCommand) HandleServer(s *Server) {
} }
func (m *TopicCommand) 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 { if user == nil {
m.Client().Replies() <- ErrNoSuchChannel(s, m.channel) m.Client().Replies() <- ErrNoPrivileges(s)
return return
} }
@ -295,9 +292,10 @@ func (m *PrivMsgCommand) HandleServer(s *Server) {
return return
} }
user := m.Client().user user := m.User()
// Hide all users from logged-out clients.
if user == nil { if user == nil {
m.Client().Replies() <- ErrNoSuchNick(s, m.target) m.Client().Replies() <- ErrNoPrivileges(s)
return return
} }