From: Thorsten S Date: Wed, 1 May 2019 09:29:16 +0000 (+0200) Subject: fix message recording X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e8927c037cf683afc5bc9b4dba3173de7d4d5bb8;p=urlbot-v3.git fix message recording --- diff --git a/distbot/plugins/muc.py b/distbot/plugins/muc.py index 497f715..4195d3b 100644 --- a/distbot/plugins/muc.py +++ b/distbot/plugins/muc.py @@ -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() ] ))