From 44d808be8de57c61831254575e551d1d949563b2 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 25 Mar 2020 22:57:48 +0100 Subject: [PATCH] Add a "network status" command --- service.go | 28 ++++++++++++++++++++++++++++ soju.1.scd | 3 +++ 2 files changed, 31 insertions(+) diff --git a/service.go b/service.go index 3938741..268afb6 100644 --- a/service.go +++ b/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 +} diff --git a/soju.1.scd b/soju.1.scd index ce2a84f..8e7e9f4 100644 --- a/soju.1.scd +++ b/soju.1.scd @@ -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 , who is assisted by other