Add a "network status" command

This commit is contained in:
Simon Ser 2020-03-25 22:57:48 +01:00
parent 448464b0e4
commit 44d808be8d
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 31 additions and 0 deletions

View File

@ -93,6 +93,10 @@ func init() {
desc: "add a new network", desc: "add a new network",
handle: handleServiceCreateNetwork, 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())) sendServicePRIVMSG(dc, fmt.Sprintf("created network %s successfully", network.GetName()))
return nil 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
}

View File

@ -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 Connect with the specified nickname. By default, the account's username
is used. is used.
*network status*
Show a list of saved networks and their current status.
# AUTHORS # AUTHORS
Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other