3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

list command

This commit is contained in:
Jeremy Latt 2014-02-16 23:51:27 -08:00
parent a9d7f64693
commit f0fc3b492c
4 changed files with 59 additions and 0 deletions

View File

@ -24,6 +24,7 @@ var (
ISON: NewIsOnCommand,
JOIN: NewJoinCommand,
KICK: NewKickCommand,
LIST: NewListCommand,
MODE: NewModeCommand,
MOTD: NewMOTDCommand,
NICK: NewNickCommand,
@ -778,3 +779,20 @@ func NewKickCommand(args []string) (editableCommand, error) {
}
return cmd, nil
}
type ListCommand struct {
BaseCommand
channels []string
target string
}
func NewListCommand(args []string) (editableCommand, error) {
cmd := &ListCommand{}
if len(args) > 0 {
cmd.channels = strings.Split(args[0], ",")
}
if len(args) > 1 {
cmd.target = args[1]
}
return cmd, nil
}

View File

@ -31,6 +31,7 @@ const (
ISON StringCode = "ISON"
JOIN StringCode = "JOIN"
KICK StringCode = "KICK"
LIST StringCode = "LIST"
MODE StringCode = "MODE"
MOTD StringCode = "MOTD"
NICK StringCode = "NICK"

View File

@ -321,6 +321,15 @@ func RplMOTDEnd(server *Server) Reply {
":End of MOTD command")
}
func RplList(channel *Channel) Reply {
return NewNumericReply(channel.server, RPL_LIST, "%s %d :%s",
channel, len(channel.members), channel.topic)
}
func RplListEnd(server *Server) Reply {
return NewNumericReply(server, RPL_LISTEND, ":End of LIST")
}
//
// errors (also numeric)
//

View File

@ -561,3 +561,34 @@ func (msg *KickCommand) HandleServer(server *Server) {
channel.Kick(client, target, msg.Comment())
}
}
func (msg *ListCommand) HandleServer(server *Server) {
client := msg.Client()
// TODO target server
if msg.target != "" {
client.Reply(ErrNoSuchServer(server, msg.target))
return
}
if len(msg.channels) == 0 {
for _, channel := range server.channels {
if channel.flags[Secret] || channel.flags[Private] {
continue
}
client.Reply(RplList(channel))
}
} else {
for _, chname := range msg.channels {
channel := server.channels[chname]
if channel == nil ||
channel.flags[Secret] ||
channel.flags[Private] {
client.Reply(ErrNoSuchChannel(server, chname))
continue
}
client.Reply(RplList(channel))
}
}
client.Reply(RplListEnd(server))
}