Merge pull request #353 from pavelz/show_admin_status
/whois: Show op status for ops
This commit is contained in:
commit
208a6a4712
3
host.go
3
host.go
|
@ -407,12 +407,11 @@ func (h *Host) InitCommands(c *chat.Commands) {
|
|||
if !ok {
|
||||
return errors.New("user not found")
|
||||
}
|
||||
|
||||
id := target.Identifier.(*Identity)
|
||||
var whois string
|
||||
switch room.IsOp(msg.From()) {
|
||||
case true:
|
||||
whois = id.WhoisAdmin()
|
||||
whois = id.WhoisAdmin(room)
|
||||
case false:
|
||||
whois = id.Whois()
|
||||
}
|
||||
|
|
12
identity.go
12
identity.go
|
@ -4,6 +4,7 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/shazow/ssh-chat/chat"
|
||||
"github.com/shazow/ssh-chat/chat/message"
|
||||
"github.com/shazow/ssh-chat/internal/humantime"
|
||||
"github.com/shazow/ssh-chat/internal/sanitize"
|
||||
|
@ -59,15 +60,22 @@ func (i Identity) Whois() string {
|
|||
}
|
||||
|
||||
// WhoisAdmin returns a whois description for admin users.
|
||||
func (i Identity) WhoisAdmin() string {
|
||||
func (i Identity) WhoisAdmin(room *chat.Room) string {
|
||||
ip, _, _ := net.SplitHostPort(i.RemoteAddr().String())
|
||||
fingerprint := "(no public key)"
|
||||
if i.PublicKey() != nil {
|
||||
fingerprint = sshd.Fingerprint(i.PublicKey())
|
||||
}
|
||||
|
||||
isOp := ""
|
||||
if member, ok := room.MemberByID(i.ID()); ok && room.IsOp(member.User) {
|
||||
isOp = message.Newline + " > op: true"
|
||||
}
|
||||
|
||||
return "name: " + i.Name() + message.Newline +
|
||||
" > ip: " + ip + message.Newline +
|
||||
" > fingerprint: " + fingerprint + message.Newline +
|
||||
" > client: " + sanitize.Data(string(i.ClientVersion()), 64) + message.Newline +
|
||||
" > joined: " + humantime.Since(i.created) + " ago"
|
||||
" > joined: " + humantime.Since(i.created) + " ago" +
|
||||
isOp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue