]> git.aero2k.de Git - urlbot-v3.git/commitdiff
fix message recording
authorThorsten S <mail@aero2k.de>
Wed, 1 May 2019 09:29:16 +0000 (11:29 +0200)
committerThorsten S <mail@aero2k.de>
Wed, 1 May 2019 09:32:37 +0000 (11:32 +0200)
distbot/plugins/muc.py

index 497f7159041850b4646db5a1b11e21cafe6f08b2..4195d3b609bcae83118e1a474ea4a56e13a4b83f 100644 (file)
@@ -2,7 +2,7 @@
 """
 MUC related plugins
 """
-
+import logging
 import time
 
 from distbot.bot.worker import Worker
@@ -16,6 +16,7 @@ from distbot.common.message import get_nick_from_message, get_words
 class Recorder(Worker):
     binding_keys = [
        "nick.show.records.*",
+       # "nick.dump.records.*",
        "nick.record.*.#",
        "nick.record.*.that",
        "nick.record.*.previous",
@@ -31,7 +32,6 @@ class Recorder(Worker):
     uses_history = True
 
     def callback(self, ch, method, properties, body):
-        self.used_channel = method.routing_key.split(".")
         super(Recorder, self).callback(ch, method, properties, body)
 
     @staticmethod
@@ -48,33 +48,40 @@ class Recorder(Worker):
 
         if cmd[0] == "userjoin":
             user = sender
-            records = conf_get("user_records.{}".format(user))
+            records = conf_get("user_records.{}".format(user)) or []
+            logging.debug("found %d records for user %s", len(records), user)
             if not records:
                 return
             else:
-                msg = '%s, there %s %d message%s for you:\n%s' % (
+                message = '%s, there %s %d message%s for you:\n%s' % (
                     user,
                     'is' if len(records) == 1 else 'are',
                     len(records),
                     '' if len(records) == 1 else 's',
                     '\n'.join(records)
                 )
-            conf_set("user_records.{}".format(user), [])
-            return Action(msg=msg)
+                conf_set("user_records.{}".format(user), [])
+                return Action(msg=message, sender=sender, recipient=msg["from"].split("/")[0])
         # feels a bit clunky
         elif cmd[0] == "nick" and len(cmd) >= 3:
-            if cmd[1] == "show" and cmd[2] == "records":
-                if len(words) == 4:
-                    user = words(3)
+            if cmd[1] in ("show", "dump") and cmd[2] == "records":
+                if len(cmd) == 4:
+                    user = cmd[3]
                 else:
                     user = None
 
+                def show_or_dump(user, recordings):
+                    if cmd[1] == "show":
+                        return '%s (%d)' % (user, len(recordings))
+                    else:
+                        return "%s \n%s" % (user, "\n".join(recordings))
+
                 msg = '%s: offline records%s: %s' % (
                     sender,
                     '' if not user else ' (limited to %s)' % user,
                     ', '.join(
                         [
-                            '%s (%d)' % (key, len(val)) for key, val in conf_get('user_records').items()
+                            show_or_dump(user, val) for key, val in conf_get('user_records').items()
                             if not user or user.lower() in key.lower()
                         ]
                     ))