diff --git a/irc/commands.go b/irc/commands.go index 62676a2d..77224e4b 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -20,6 +20,7 @@ var ( parseCommandFuncs = map[string]parseCommandFunc{ "AWAY": NewAwayCommand, "CAP": NewCapCommand, + "ISON": NewIsOnCommand, "JOIN": NewJoinCommand, "MODE": NewModeCommand, "NICK": NewNickCommand, @@ -631,3 +632,22 @@ func NewAwayCommand(args []string) (editableCommand, error) { return cmd, nil } + +type IsOnCommand struct { + BaseCommand + nicks []string +} + +func (msg *IsOnCommand) String() string { + return fmt.Sprintf("ISON(nicks=%s)", msg.nicks) +} + +func NewIsOnCommand(args []string) (editableCommand, error) { + if len(args) == 0 { + return nil, NotEnoughArgsError + } + + return &IsOnCommand{ + nicks: args, + }, nil +} diff --git a/irc/reply.go b/irc/reply.go index f275e373..5b7c5072 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -271,7 +271,14 @@ func RplAway(server *Server, client *Client) Reply { "%s :%s", client.nick, client.awayMessage) } +func RplIsOn(server *Server, nicks []string) Reply { + return NewNumericReply(server, RPL_ISON, + ":%s", strings.Join(nicks, " ")) +} + +// // errors (also numeric) +// func ErrAlreadyRegistered(source Identifier) Reply { return NewNumericReply(source, ERR_ALREADYREGISTRED, diff --git a/irc/server.go b/irc/server.go index f519cb72..11b96f5d 100644 --- a/irc/server.go +++ b/irc/server.go @@ -422,3 +422,16 @@ func (msg *AwayCommand) HandleServer(server *Server) { client.Reply(RplUnAway(server)) } } + +func (msg *IsOnCommand) HandleServer(server *Server) { + client := msg.Client() + + ison := make([]string, 0) + for _, nick := range msg.nicks { + if _, ok := server.clients[nick]; ok { + ison = append(ison, nick) + } + } + + client.Reply(RplIsOn(server, ison)) +}