mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
systemd support and separate message queues per room
This commit is contained in:
2
deploy/requirements-deploy.yml
Normal file
2
deploy/requirements-deploy.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
ansible
|
||||
markupsafe
|
||||
12
deploy/urlbug@.service
Normal file
12
deploy/urlbug@.service
Normal file
@@ -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
|
||||
@@ -801,9 +801,9 @@ 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'}
|
||||
if args['stack']:
|
||||
return {
|
||||
'msg': args['stack'][-1]['body']
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
11
urlbot.py
11
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:
|
||||
|
||||
Reference in New Issue
Block a user