ison command

This commit is contained in:
Jeremy Latt 2014-02-11 15:58:54 -08:00
parent 08d9d5ab79
commit a203a3ca16
3 changed files with 40 additions and 0 deletions

View File

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

View File

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

View File

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