diff --git a/irc/client.go b/irc/client.go index f96d6ff0..e5c04463 100644 --- a/irc/client.go +++ b/irc/client.go @@ -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 != "" } diff --git a/irc/reply.go b/irc/reply.go index 640106e4..1ce42521 100644 --- a/irc/reply.go +++ b/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") } diff --git a/irc/server.go b/irc/server.go index 790d899c..b5199ce2 100644 --- a/irc/server.go +++ b/irc/server.go @@ -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) {