Browse Source

add !identify command

Helge Jung 9 years ago
parent
commit
273e8a4d50
2 changed files with 38 additions and 0 deletions
  1. 4 0
      modules/batcave/client.py
  2. 34 0
      modules/ffpb_nodeinfo.py

+ 4 - 0
modules/batcave/client.py

@@ -89,3 +89,7 @@ class BatcaveClient(object):
     def get_status(self):
         url = 'status.json'
         return self.__load_response(url, 'status')
+
+    def identify(self, ident):
+        url = 'identify?ident=' + str(ident)
+        return self.__load_response(url, 'identify \'' + ident + '\'')

+ 34 - 0
modules/ffpb_nodeinfo.py

@@ -6,11 +6,18 @@ import willie
 from ffpb import \
     ffpb_findnode_from_botparam, \
     mac2ipv6, playitsafe, pretty_date
+from batcave import BatcaveClient
 
 
+__batcave = None
+
 def setup(bot):
     """Called by willie upon loading this plugin."""
 
+    global __batcave, highscores
+
+    __batcave = BatcaveClient(bot.config.ffpb.batcave_url)
+
     pass
 
 
@@ -20,6 +27,33 @@ def shutdown(bot):
     pass
 
 
+@willie.module.commands('identify')
+def ffpb_identify(bot, trigger):
+    """Identify node."""
+
+    # query must be as OP in the channel
+    if not playitsafe(bot, trigger, via_channel=True, need_op=True):
+        # the check function already gives a bot reply, just exit here
+        return
+
+    ident = trigger.group(2)
+    result = __batcave.identify(ident)
+    if result is None:
+        bot.say('Mist, ich erreiche den Detektiv nicht.')
+        return
+
+    if not ident in result:
+        bot.say('Mein Detektiv hat getrunken und erzählt Blödsinn.')
+        return
+
+    if len(result[ident]) == 0:
+        bot.say('Trotz intensivster Recherche habe ich zu "%s" nix gefunden :/' % ident)
+    elif len(result[ident]) == 1:
+        bot.say('Glasklar, "%s" wurde identifiziert: %s' % (ident, result[ident][0]))
+    else:
+        bot.say('Hm, zu "%s" gibt es mehrere Möglichkeiten: %s' % (ident, str.join(', ', result[ident])))
+
+
 @willie.module.commands('raw-data')
 def ffpb_peerdata(bot, trigger):
     """Show ALFRED data of the given node."""