"""
MUC related plugins
"""
-
+import logging
import time
from distbot.bot.worker import Worker
class Recorder(Worker):
binding_keys = [
"nick.show.records.*",
+ # "nick.dump.records.*",
"nick.record.*.#",
"nick.record.*.that",
"nick.record.*.previous",
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
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()
]
))