Browse Source

changed !info output to include node's status if it's not active

Helge Jung 9 years ago
parent
commit
5f05c1ff33
1 changed files with 16 additions and 16 deletions
  1. 16 16
      modules/ffpb_nodeinfo.py

+ 16 - 16
modules/ffpb_nodeinfo.py

@@ -56,27 +56,27 @@ def ffpb_peerinfo(bot, trigger):
     if node is None:
         return
 
+    output = []
+
     # read node information
     info_mac = node.get('network', {}).get('mac', '??:??:??:??:??:??')
     info_id = node.get('node_id', info_mac.replace(':', ''))
     info_name = node.get('hostname', '?-' + info_id)
 
-    info_hw = ""
+    output.append("[" + info_name + "]")
+
     if "hardware" in node:
         model = node["hardware"]
-        info_hw = " model='" + model + "'"
+        output.append("model='" + model + "'")
 
-    info_fw = ""
-    info_update = ""
     if "software" in node:
         if "firmware" in node["software"]:
-            info_fw = " firmware=" + str(node["software"]["firmware"])
+            output.append("firmware=" + str(node["software"]["firmware"]))
 
         if "autoupdater" in node["software"]:
             autoupdater = node["software"]["autoupdater"]
-            info_update = " (autoupdater="+autoupdater+")"
+            output.append("(autoupdater="+autoupdater+")")
 
-    info_uptime = ""
     uptime = node.get('uptime', -1)
 
     if uptime > 0:
@@ -84,22 +84,22 @@ def ffpb_peerinfo(bot, trigger):
         hours, rem_h = divmod(rem_d, 3600)
         minutes, _ = divmod(rem_h, 60)
         if days > 0:
-            info_uptime = ' up {0}d {1}h'.format(days, hours)
+            output.append('up {0}d {1}h'.format(days, hours))
         elif hours > 0:
-            info_uptime = ' up {0}h {1}m'.format(hours, minutes)
+            output.append('up {0}h {1}m'.format(hours, minutes))
         else:
-            info_uptime = ' up {0}m'.format(minutes)
+            output.append('up {0}m'.format(minutes))
 
-    info_clients = ""
     clientcount = node.get('clientcount')
     if not clientcount is None:
         clientcount = int(clientcount)
-        info_clients = ' clients={0}'.format(clientcount)
+        output.append('clients={0}'.format(clientcount))
+
+    nodestatus = node.get('status', 'unknown')
+    if nodestatus != 'active':
+        output.append("[" + nodestatus.upper() + "]")
 
-    bot.say('[{1}]{2}{3}{4}{5}{6}'.format(
-            info_mac, info_name,
-            info_hw, info_fw, info_update,
-            info_uptime, info_clients))
+    bot.say(str.join(" ", output))
 
 
 @willie.module.commands('last-seen')