Add a "network status" command
This commit is contained in:
parent
448464b0e4
commit
44d808be8d
28
service.go
28
service.go
@ -93,6 +93,10 @@ func init() {
|
||||
desc: "add a new network",
|
||||
handle: handleServiceCreateNetwork,
|
||||
},
|
||||
"status": {
|
||||
desc: "show a list of saved networks and their current status",
|
||||
handle: handleServiceNetworkStatus,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -176,3 +180,27 @@ func handleServiceCreateNetwork(dc *downstreamConn, params []string) error {
|
||||
sendServicePRIVMSG(dc, fmt.Sprintf("created network %s successfully", network.GetName()))
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleServiceNetworkStatus(dc *downstreamConn, params []string) error {
|
||||
dc.user.forEachNetwork(func(net *network) {
|
||||
var statuses []string
|
||||
var details string
|
||||
if uc := net.upstream(); uc != nil {
|
||||
statuses = append(statuses, "connected as "+uc.nick)
|
||||
details = fmt.Sprintf("%v channels", len(uc.channels))
|
||||
} else {
|
||||
statuses = append(statuses, "disconnected")
|
||||
}
|
||||
|
||||
if net == dc.network {
|
||||
statuses = append(statuses, "current")
|
||||
}
|
||||
|
||||
s := fmt.Sprintf("%v (%v) [%v]", net.GetName(), net.Addr, strings.Join(statuses, ", "))
|
||||
if details != "" {
|
||||
s += ": " + details
|
||||
}
|
||||
sendServicePRIVMSG(dc, s)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
@ -101,6 +101,9 @@ abbreviated form, for instance *network* can be abbreviated as *net* or just
|
||||
Connect with the specified nickname. By default, the account's username
|
||||
is used.
|
||||
|
||||
*network status*
|
||||
Show a list of saved networks and their current status.
|
||||
|
||||
# AUTHORS
|
||||
|
||||
Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other
|
||||
|
Loading…
Reference in New Issue
Block a user