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

notice command

This commit is contained in:
Jeremy Latt 2014-02-11 17:11:59 -08:00
parent 09887b2db3
commit 6daf81ea91
5 changed files with 55 additions and 0 deletions

View File

@ -241,3 +241,12 @@ func (msg *ChannelModeCommand) HandleChannel(channel *Channel) {
client.Reply(RplChannelModeIs(channel))
}
func (m *NoticeCommand) HandleChannel(channel *Channel) {
client := m.Client()
if channel.noOutside && !channel.members.Has(client) {
client.Reply(ErrCannotSendToChan(channel))
return
}
channel.Reply(RplNotice(client, channel, m.message))
}

View File

@ -25,6 +25,7 @@ var (
"MODE": NewModeCommand,
"MOTD": NewMOTDCommand,
"NICK": NewNickCommand,
"NOTICE": NewNoticeCommand,
"OPER": NewOperCommand,
"PART": NewPartCommand,
"PASS": NewPassCommand,
@ -665,3 +666,23 @@ func NewMOTDCommand(args []string) (editableCommand, error) {
}
return cmd, nil
}
type NoticeCommand struct {
BaseCommand
target string
message string
}
func (cmd *NoticeCommand) String() string {
return fmt.Sprintf("NOTICE(target=%s, message=%s)", cmd.target, cmd.message)
}
func NewNoticeCommand(args []string) (editableCommand, error) {
if len(args) < 2 {
return nil, NotEnoughArgsError
}
return &NoticeCommand{
target: args[0],
message: args[1],
}, nil
}

View File

@ -167,6 +167,7 @@ const (
RPL_INVITE = "INVITE"
RPL_JOIN = "JOIN"
RPL_NICK = "NICK"
RPL_NOTICE = "NOTICE"
RPL_PART = "PART"
RPL_PING = "PING"
RPL_PONG = "PONG"

View File

@ -128,6 +128,10 @@ func RplPrivMsg(source Identifier, target Identifier, message string) Reply {
return NewStringReply(source, RPL_PRIVMSG, "%s :%s", target.Nick(), message)
}
func RplNotice(source Identifier, target Identifier, message string) Reply {
return NewStringReply(source, RPL_NOTICE, "%s :%s", target.Nick(), message)
}
func RplNick(source Identifier, newNick string) Reply {
return NewStringReply(source, RPL_NICK, newNick)
}

View File

@ -475,3 +475,23 @@ func (msg *IsOnCommand) HandleServer(server *Server) {
func (msg *MOTDCommand) HandleServer(server *Server) {
server.MOTD(msg.Client())
}
func (msg *NoticeCommand) HandleServer(server *Server) {
if IsChannel(msg.target) {
channel := server.channels[msg.target]
if channel == nil {
msg.Client().Reply(ErrNoSuchChannel(server, msg.target))
return
}
channel.commands <- msg
return
}
target := server.clients[msg.target]
if target == nil {
msg.Client().Reply(ErrNoSuchNick(server, msg.target))
return
}
target.Reply(RplPrivMsg(msg.Client(), target, msg.message))
}