Changeset 151 in code


Ignore:
Timestamp:
Mar 25, 2020, 9:57:48 PM (5 years ago)
Author:
contact
Message:

Add a "network status" command

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/service.go

    r150 r151  
    9494                                        handle: handleServiceCreateNetwork,
    9595                                },
     96                                "status": {
     97                                        desc:   "show a list of saved networks and their current status",
     98                                        handle: handleServiceNetworkStatus,
     99                                },
    96100                        },
    97101                },
     
    177181        return nil
    178182}
     183
     184func handleServiceNetworkStatus(dc *downstreamConn, params []string) error {
     185        dc.user.forEachNetwork(func(net *network) {
     186                var statuses []string
     187                var details string
     188                if uc := net.upstream(); uc != nil {
     189                        statuses = append(statuses, "connected as "+uc.nick)
     190                        details = fmt.Sprintf("%v channels", len(uc.channels))
     191                } else {
     192                        statuses = append(statuses, "disconnected")
     193                }
     194
     195                if net == dc.network {
     196                        statuses = append(statuses, "current")
     197                }
     198
     199                s := fmt.Sprintf("%v (%v) [%v]", net.GetName(), net.Addr, strings.Join(statuses, ", "))
     200                if details != "" {
     201                        s += ": " + details
     202                }
     203                sendServicePRIVMSG(dc, s)
     204        })
     205        return nil
     206}
  • trunk/soju.1.scd

    r150 r151  
    102102                is used.
    103103
     104*network status*
     105        Show a list of saved networks and their current status.
     106
    104107# AUTHORS
    105108
Note: See TracChangeset for help on using the changeset viewer.