diff --git a/irc/channel.go b/irc/channel.go index 41f7ed14..e9c59bce 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -49,8 +49,8 @@ func (channel *Channel) IsEmpty() bool { return len(channel.members) == 0 } -func (channel *Channel) GetUsers(replier Replier) { - replier.Reply(NewNamesReply(channel)) +func (channel *Channel) Names(client *Client) { + client.Reply(NewNamesReply(channel)) } func (channel *Channel) ClientIsOperator(client *Client) bool { @@ -128,7 +128,7 @@ func (channel *Channel) Join(client *Client, key string) { channel.Reply(RplJoin(client, channel)) channel.GetTopic(client) - channel.GetUsers(client) + channel.Names(client) } func (channel *Channel) Part(client *Client, message string) { diff --git a/irc/commands.go b/irc/commands.go index a00fc68c..db9724d3 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -27,6 +27,7 @@ var ( LIST: NewListCommand, MODE: NewModeCommand, MOTD: NewMOTDCommand, + NAMES: NewNamesCommand, NICK: NewNickCommand, NOTICE: NewNoticeCommand, OPER: NewOperCommand, @@ -807,3 +808,20 @@ func NewListCommand(args []string) (editableCommand, error) { } return cmd, nil } + +type NamesCommand struct { + BaseCommand + channels []string + target string +} + +func NewNamesCommand(args []string) (editableCommand, error) { + cmd := &NamesCommand{} + if len(args) > 0 { + cmd.channels = strings.Split(args[0], ",") + } + if len(args) > 1 { + cmd.target = args[1] + } + return cmd, nil +} diff --git a/irc/constants.go b/irc/constants.go index 10e14221..e731d05b 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -42,6 +42,7 @@ const ( LIST StringCode = "LIST" MODE StringCode = "MODE" MOTD StringCode = "MOTD" + NAMES StringCode = "NAMES" NICK StringCode = "NICK" NOTICE StringCode = "NOTICE" OPER StringCode = "OPER" diff --git a/irc/server.go b/irc/server.go index 2eea338f..d3caa842 100644 --- a/irc/server.go +++ b/irc/server.go @@ -629,3 +629,22 @@ func (msg *ClientIdle) HandleServer(server *Server) { client := msg.Client() client.Reply(RplPing(server, client)) } + +func (msg *NamesCommand) HandleServer(server *Server) { + client := msg.Client() + if len(server.channels) == 0 { + for _, channel := range server.channels { + channel.Names(client) + } + return + } + + for _, chname := range msg.channels { + channel := server.channels[chname] + if channel == nil { + client.Reply(ErrNoSuchChannel(server, chname)) + continue + } + channel.Names(client) + } +}