mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
minimal who command
This commit is contained in:
parent
d8951e1b48
commit
d370abcd4c
@ -18,6 +18,13 @@ type Channel struct {
|
|||||||
|
|
||||||
type ChannelSet map[*Channel]bool
|
type ChannelSet map[*Channel]bool
|
||||||
|
|
||||||
|
func (channels ChannelSet) First() *Channel {
|
||||||
|
for channel := range channels {
|
||||||
|
return channel
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type ChannelCommand interface {
|
type ChannelCommand interface {
|
||||||
Command
|
Command
|
||||||
HandleChannel(channel *Channel)
|
HandleChannel(channel *Channel)
|
||||||
|
@ -35,6 +35,7 @@ var (
|
|||||||
"QUIT": NewQuitCommand,
|
"QUIT": NewQuitCommand,
|
||||||
"TOPIC": NewTopicCommand,
|
"TOPIC": NewTopicCommand,
|
||||||
"USER": NewUserMsgCommand,
|
"USER": NewUserMsgCommand,
|
||||||
|
"WHO": NewWhoCommand,
|
||||||
"WHOIS": NewWhoisCommand,
|
"WHOIS": NewWhoisCommand,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -485,7 +486,7 @@ type WhoisCommand struct {
|
|||||||
masks []string
|
masks []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ <target> ] <mask> *( "," <mask> )
|
// WHOIS [ <target> ] <mask> *( "," <mask> )
|
||||||
func NewWhoisCommand(args []string) (EditableCommand, error) {
|
func NewWhoisCommand(args []string) (EditableCommand, error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return nil, NotEnoughArgsError
|
return nil, NotEnoughArgsError
|
||||||
@ -506,3 +507,24 @@ func NewWhoisCommand(args []string) (EditableCommand, error) {
|
|||||||
masks: strings.Split(masks, ","),
|
masks: strings.Split(masks, ","),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WhoCommand struct {
|
||||||
|
BaseCommand
|
||||||
|
mask string
|
||||||
|
operatorOnly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// WHO [ <mask> [ "o" ] ]
|
||||||
|
func NewWhoCommand(args []string) (EditableCommand, error) {
|
||||||
|
cmd := &WhoCommand{}
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
cmd.mask = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len(args) > 1) && (args[1] == "o") {
|
||||||
|
cmd.operatorOnly = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd, nil
|
||||||
|
}
|
||||||
|
13
irc/reply.go
13
irc/reply.go
@ -239,6 +239,19 @@ func RplChannelModeIs(server *Server, channel *Channel) Reply {
|
|||||||
channel.name, channel.ModeString())
|
channel.name, channel.ModeString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <channel> <user> <host> <server> <nick> ( "H" / "G" ) ["*"] [ ( "@" / "+" ) ]
|
||||||
|
// :<hopcount> <real name>
|
||||||
|
func RplWhoReply(server *Server, channel *Channel, client *Client) Reply {
|
||||||
|
return NewNumericReply(server, RPL_WHOREPLY, "%s %s %s %s %s H :0 %s",
|
||||||
|
channel.name, client.username, client.hostname, server.name, client.nick,
|
||||||
|
client.realname)
|
||||||
|
}
|
||||||
|
|
||||||
|
// <name> :End of WHO list
|
||||||
|
func RplEndOfWho(server *Server, name string) Reply {
|
||||||
|
return NewNumericReply(server, RPL_ENDOFWHO, "%s :End of WHO list", name)
|
||||||
|
}
|
||||||
|
|
||||||
// errors (also numeric)
|
// errors (also numeric)
|
||||||
|
|
||||||
func ErrAlreadyRegistered(source Identifier) Reply {
|
func ErrAlreadyRegistered(source Identifier) Reply {
|
||||||
|
@ -310,3 +310,32 @@ func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
|||||||
|
|
||||||
client.replies <- RplChannelModeIs(server, channel)
|
client.replies <- RplChannelModeIs(server, channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func whoChannel(client *Client, server *Server, channel *Channel) {
|
||||||
|
for member := range channel.members {
|
||||||
|
client.replies <- RplWhoReply(server, channel, member)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (msg *WhoCommand) HandleServer(server *Server) {
|
||||||
|
client := msg.Client()
|
||||||
|
// TODO implement wildcard matching
|
||||||
|
|
||||||
|
if msg.mask == "" {
|
||||||
|
for _, channel := range server.channels {
|
||||||
|
whoChannel(client, server, channel)
|
||||||
|
}
|
||||||
|
} else if IsChannel(msg.mask) {
|
||||||
|
channel := server.channels[msg.mask]
|
||||||
|
if channel != nil {
|
||||||
|
whoChannel(client, server, channel)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mclient := server.clients[msg.mask]
|
||||||
|
if mclient != nil {
|
||||||
|
client.replies <- RplWhoReply(server, mclient.channels.First(), mclient)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.replies <- RplEndOfWho(server, msg.mask)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user