diff --git a/deploy/requirements-deploy.yml b/deploy/requirements-deploy.yml new file mode 100644 index 0000000..7547399 --- /dev/null +++ b/deploy/requirements-deploy.yml @@ -0,0 +1,2 @@ +ansible +markupsafe diff --git a/deploy/urlbug@.service b/deploy/urlbug@.service new file mode 100644 index 0000000..7c8f923 --- /dev/null +++ b/deploy/urlbug@.service @@ -0,0 +1,12 @@ +[Unit] +Description=jabber bot entertaining and supporting activity on jabber MUCs + +[Service] +ExecStart=/home/jabberbot/botenv/bin/python3 /home/jabberbot/urlbot/%i.py +WorkingDirectory=/home/jabberbot/urlbot/ +StandardOutput=journal+console +StandardError=journal+console +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/plugins/commands.py b/plugins/commands.py index 5d9c34f..898cf06 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -801,12 +801,12 @@ def raise_an_error(argv, **args): raise RuntimeError("Exception for debugging") -@pluginfunction('repeat', 'repeat the last message', ptypes.COMMAND, enabled=False) +@pluginfunction('repeat', 'repeat the last message', ptypes.COMMAND) def repeat_message(argv, **args): - return {'msg': 'disabled until channel separation'} - return { - 'msg': args['stack'][-1]['body'] - } + if args['stack']: + return { + 'msg': args['stack'][-1]['body'] + } @pluginfunction('isdown', 'check if a website is reachable', ptypes.COMMAND) diff --git a/plugins/translate.py b/plugins/translate.py index 701faea..dcdbda4 100644 --- a/plugins/translate.py +++ b/plugins/translate.py @@ -22,6 +22,8 @@ def translate(argv, **args): if not api_key: return message_stack = args['stack'] + if not message_stack[-1]: + return last_message = message_stack[-1]['body'] data = { 'q': last_message, diff --git a/urlbot.py b/urlbot.py index a1f3a43..96ec0d3 100755 --- a/urlbot.py +++ b/urlbot.py @@ -7,6 +7,8 @@ import re import shlex import sys import time +from collections import deque + from lxml import etree import requests @@ -34,7 +36,7 @@ class UrlBot(IdleBot): self.hist_ts = {p: [] for p in rate_limit_classes} self.hist_flag = {p: True for p in rate_limit_classes} - self.message_stack = [] + self.message_stack = {str(room): deque(maxlen=5) for room in self.rooms} self.add_event_handler('message', self.message) self.priority = 100 @@ -196,9 +198,8 @@ class UrlBot(IdleBot): except Exception as e: self.logger.exception(e) finally: - if len(self.message_stack) > 4: - self.message_stack.pop(0) - self.message_stack.append(msg_obj) + if msg_obj['from'].bare in self.rooms: + self.message_stack[msg_obj['from'].bare].append(msg_obj) def handle_muc_online(self, msg_obj): """ @@ -268,7 +269,7 @@ class UrlBot(IdleBot): reply_user=reply_user, msg_obj=msg_obj, argv=words[2:] if len(words) > 1 else [], - stack=self.message_stack + stack=self.message_stack.get(msg_obj['from'].bare, []) ) if ret: