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

WHOWAS command

This commit is contained in:
Jeremy Latt 2014-03-06 12:14:21 -08:00
parent 69cdad45ac
commit b2055595e1
4 changed files with 49 additions and 0 deletions

View File

@ -54,6 +54,7 @@ var (
VERSION: NewVersionCommand,
WHO: NewWhoCommand,
WHOIS: NewWhoisCommand,
WHOWAS: NewWhoWasCommand,
}
)
@ -968,3 +969,26 @@ func NewKillCommand(args []string) (editableCommand, error) {
comment: args[1],
}, nil
}
type WhoWasCommand struct {
BaseCommand
nicknames []string
count int64
target string
}
func NewWhoWasCommand(args []string) (editableCommand, error) {
if len(args) < 1 {
return nil, NotEnoughArgsError
}
cmd := &WhoWasCommand{
nicknames: strings.Split(args[0], ","),
}
if len(args) > 1 {
cmd.count, _ = strconv.ParseInt(args[1], 10, 64)
}
if len(args) > 2 {
cmd.target = args[2]
}
return cmd, nil
}

View File

@ -61,6 +61,7 @@ const (
VERSION StringCode = "VERSION"
WHO StringCode = "WHO"
WHOIS StringCode = "WHOIS"
WHOWAS StringCode = "WHOWAS"
// numeric codes
RPL_WELCOME NumericCode = 1

View File

@ -394,6 +394,16 @@ func (target *Client) RplTime() {
"%s :%s", target.server.name, time.Now().Format(time.RFC1123))
}
func (target *Client) RplWhoWasUser(nickname, username, hostname, realname string) {
target.NumericReply(RPL_WHOWASUSER,
"%s %s %s * :%s", nickname, username, hostname, realname)
}
func (target *Client) RplEndOfWhoWas(nickname string) {
target.NumericReply(RPL_ENDOFWHOWAS,
"%s :End of WHOWAS", nickname)
}
//
// errors (also numeric)
//
@ -512,3 +522,8 @@ func (target *Client) ErrChannelIsFull(channel *Channel) {
target.NumericReply(ERR_CHANNELISFULL,
"%s :Cannot join channel (+l)", channel)
}
func (target *Client) ErrWasNoSuchNick(nickname string) {
target.NumericReply(ERR_WASNOSUCHNICK,
"%s :There was no such nickname", nickname)
}

View File

@ -844,6 +844,15 @@ func (msg *KillCommand) HandleServer(server *Server) {
target.Quit(quitMsg)
}
func (msg *WhoWasCommand) HandleServer(server *Server) {
client := msg.Client()
for _, nickname := range msg.nicknames {
// TODO implement nick history
client.ErrWasNoSuchNick(nickname)
client.RplEndOfWhoWas(nickname)
}
}
//
// keeping track of clients
//