3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 03:49:27 +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) {
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)
}

View File

@ -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
}

View File

@ -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
}