mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-13 07:29:30 +01:00
beef up whois
This commit is contained in:
parent
bd3ca4ae47
commit
9a5f21e78c
@ -165,6 +165,10 @@ func (client *Client) IdleTime() time.Duration {
|
||||
return time.Since(client.atime)
|
||||
}
|
||||
|
||||
func (client *Client) IdleSeconds() uint64 {
|
||||
return uint64(client.IdleTime().Seconds())
|
||||
}
|
||||
|
||||
func (client *Client) HasNick() bool {
|
||||
return client.nick != ""
|
||||
}
|
||||
|
32
irc/reply.go
32
irc/reply.go
@ -246,11 +246,39 @@ func RplYoureOper(server *Server) Reply {
|
||||
return NewNumericReply(server, RPL_YOUREOPER, ":You are now an IRC operator")
|
||||
}
|
||||
|
||||
func RplWhoisUser(server *Server, client *Client) Reply {
|
||||
return NewNumericReply(server, RPL_WHOISUSER, "%s %s %s * :%s",
|
||||
func RplWhoisUser(client *Client) Reply {
|
||||
return NewNumericReply(client.server, RPL_WHOISUSER, "%s %s %s * :%s",
|
||||
client.Nick(), client.username, client.hostname, client.realname)
|
||||
}
|
||||
|
||||
func RplWhoisOperator(client *Client) Reply {
|
||||
return NewNumericReply(client.server, RPL_WHOISOPERATOR,
|
||||
"%s :is an IRC operator", client.Nick())
|
||||
}
|
||||
|
||||
func RplWhoisIdle(client *Client) Reply {
|
||||
return NewNumericReply(client.server, RPL_WHOISIDLE,
|
||||
"%s %d :seconds idle", client.Nick(), client.IdleSeconds())
|
||||
}
|
||||
|
||||
// TODO check message length
|
||||
func RplWhoisChannels(client *Client) Reply {
|
||||
chstrs := make([]string, len(client.channels))
|
||||
index := 0
|
||||
for channel := range client.channels {
|
||||
if channel.members[client][ChannelOperator] {
|
||||
chstrs[index] = "@" + channel.name
|
||||
} else if channel.members[client][Voice] {
|
||||
chstrs[index] = "+" + channel.name
|
||||
} else {
|
||||
chstrs[index] = channel.name
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return NewNumericReply(client.server, RPL_WHOISCHANNELS,
|
||||
"%s :%s", client.Nick(), strings.Join(chstrs, " "))
|
||||
}
|
||||
|
||||
func RplEndOfWhois(server *Server) Reply {
|
||||
return NewNumericReply(server, RPL_ENDOFWHOIS, ":End of WHOIS list")
|
||||
}
|
||||
|
@ -451,12 +451,19 @@ func (m *WhoisCommand) HandleServer(server *Server) {
|
||||
|
||||
for _, mask := range m.masks {
|
||||
// TODO implement wildcard matching
|
||||
mclient := server.clients[mask]
|
||||
if mclient != nil {
|
||||
client.Reply(RplWhoisUser(server, mclient))
|
||||
mclient := server.clients.Get(mask)
|
||||
if mclient == nil {
|
||||
client.Reply(ErrNoSuchNick(server, mask))
|
||||
continue
|
||||
}
|
||||
client.Reply(RplWhoisUser(mclient))
|
||||
if client.flags[Operator] {
|
||||
client.Reply(RplWhoisOperator(mclient))
|
||||
}
|
||||
client.Reply(RplWhoisIdle(mclient))
|
||||
client.Reply(RplWhoisChannels(mclient))
|
||||
client.Reply(RplEndOfWhois(server))
|
||||
}
|
||||
client.Reply(RplEndOfWhois(server))
|
||||
}
|
||||
|
||||
func (msg *ChannelModeCommand) HandleServer(server *Server) {
|
||||
|
Loading…
Reference in New Issue
Block a user