mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-03 08:32:43 +01:00
notice command
This commit is contained in:
parent
09887b2db3
commit
6daf81ea91
@ -241,3 +241,12 @@ func (msg *ChannelModeCommand) HandleChannel(channel *Channel) {
|
|||||||
|
|
||||||
client.Reply(RplChannelModeIs(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))
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ var (
|
|||||||
"MODE": NewModeCommand,
|
"MODE": NewModeCommand,
|
||||||
"MOTD": NewMOTDCommand,
|
"MOTD": NewMOTDCommand,
|
||||||
"NICK": NewNickCommand,
|
"NICK": NewNickCommand,
|
||||||
|
"NOTICE": NewNoticeCommand,
|
||||||
"OPER": NewOperCommand,
|
"OPER": NewOperCommand,
|
||||||
"PART": NewPartCommand,
|
"PART": NewPartCommand,
|
||||||
"PASS": NewPassCommand,
|
"PASS": NewPassCommand,
|
||||||
@ -665,3 +666,23 @@ func NewMOTDCommand(args []string) (editableCommand, error) {
|
|||||||
}
|
}
|
||||||
return cmd, nil
|
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
|
||||||
|
}
|
||||||
|
@ -167,6 +167,7 @@ const (
|
|||||||
RPL_INVITE = "INVITE"
|
RPL_INVITE = "INVITE"
|
||||||
RPL_JOIN = "JOIN"
|
RPL_JOIN = "JOIN"
|
||||||
RPL_NICK = "NICK"
|
RPL_NICK = "NICK"
|
||||||
|
RPL_NOTICE = "NOTICE"
|
||||||
RPL_PART = "PART"
|
RPL_PART = "PART"
|
||||||
RPL_PING = "PING"
|
RPL_PING = "PING"
|
||||||
RPL_PONG = "PONG"
|
RPL_PONG = "PONG"
|
||||||
|
@ -128,6 +128,10 @@ func RplPrivMsg(source Identifier, target Identifier, message string) Reply {
|
|||||||
return NewStringReply(source, RPL_PRIVMSG, "%s :%s", target.Nick(), message)
|
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 {
|
func RplNick(source Identifier, newNick string) Reply {
|
||||||
return NewStringReply(source, RPL_NICK, newNick)
|
return NewStringReply(source, RPL_NICK, newNick)
|
||||||
}
|
}
|
||||||
|
@ -475,3 +475,23 @@ func (msg *IsOnCommand) HandleServer(server *Server) {
|
|||||||
func (msg *MOTDCommand) HandleServer(server *Server) {
|
func (msg *MOTDCommand) HandleServer(server *Server) {
|
||||||
server.MOTD(msg.Client())
|
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))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user