Compare commits
10 Commits
fa9e970eeb
...
d9d87f114a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9d87f114a | ||
|
|
4541dd0ebb | ||
|
|
efd18525bb | ||
|
|
dff83acaf6 | ||
|
|
94c78335fb | ||
|
|
d5886fbd94 | ||
|
|
f7ab2cfbdd | ||
|
|
5b9ed2ef94 | ||
|
|
5ffa3f0dc7 | ||
|
|
1c0f7a7024 |
@@ -20,6 +20,7 @@
|
||||
vars:
|
||||
- botrepo: http://aero2k.de/t/repos/urlbot-native.git
|
||||
- pypi_mirror: http://pypi.fcio.net/simple/
|
||||
- systemd: true
|
||||
tasks:
|
||||
- include_vars: credentials.yml
|
||||
tags: [render_config]
|
||||
@@ -27,6 +28,7 @@
|
||||
shell: virtualenv -p python3 --system-site-packages ~/botenv creates=~/botenv/bin/activate
|
||||
- name: virtualenv for supervisord
|
||||
shell: virtualenv -p python2 ~/svenv creates=~/svenv/bin/activate
|
||||
when: not systemd
|
||||
- name: clone repository
|
||||
git: repo="{{botrepo}}" dest=~/urlbot force=yes update=yes
|
||||
register: source_code
|
||||
@@ -34,6 +36,7 @@
|
||||
pip: requirements="~/urlbot/requirements.txt" virtualenv=~/botenv extra_args="-i {{pypi_mirror}}"
|
||||
- name: install supervisor
|
||||
pip: name=supervisor virtualenv=~/svenv extra_args="-i {{pypi_mirror}}"
|
||||
when: not systemd
|
||||
|
||||
- name: set configuration
|
||||
lineinfile: dest=~/urlbot/local_config.ini create=yes line="{{item.key}} = {{item.value}}" regexp="^{{item.key}}.="
|
||||
@@ -60,29 +63,94 @@
|
||||
- name: create supervisor config
|
||||
copy: src=supervisord.conf dest=~/supervisord.conf
|
||||
register: supervisord
|
||||
when: not systemd
|
||||
|
||||
- name: create directory for systemd unit file
|
||||
shell: mkdir -p ~/.config/systemd/user/ creates=~/.config/systemd/user/
|
||||
when: systemd
|
||||
|
||||
- name: create unitfile
|
||||
copy: src=urlbug@.service dest=~/.config/systemd/user/urlbug@.service
|
||||
when: systemd
|
||||
register: unitfile
|
||||
|
||||
# crapshit does not work
|
||||
- name: reload unitfiles
|
||||
become: true
|
||||
shell: systemctl daemon-reload
|
||||
when: unitfile.changed
|
||||
ignore_errors: true
|
||||
|
||||
- name: enable services
|
||||
shell: "systemctl --user enable urlbug@{{item}}.service"
|
||||
with_items:
|
||||
- idlebot
|
||||
- urlbot
|
||||
when: systemd
|
||||
|
||||
- name: verify supervisor running
|
||||
shell: nc -z 127.0.0.1 9004; echo $? executable=/bin/bash
|
||||
register: supervisor_running
|
||||
changed_when: false
|
||||
when: not systemd
|
||||
|
||||
- name: start supervisord
|
||||
shell: source ~/svenv/bin/activate && supervisord executable=/bin/bash
|
||||
register: start_supervisor
|
||||
when: supervisord.changed or supervisor_running.stdout == "1"
|
||||
when:
|
||||
- not systemd
|
||||
- supervisord.changed or supervisor_running.stdout == "1"
|
||||
#changed_when: "'already listening' not in start_supervisor.stdout"
|
||||
|
||||
- name: activate supervisord changes
|
||||
when: supervisord.changed
|
||||
shell: source ~/svenv/bin/activate && supervisorctl reload executable=/bin/bash
|
||||
when:
|
||||
- not systemd
|
||||
- supervisord.changed
|
||||
|
||||
- name: idlebot started
|
||||
supervisorctl: name=idlebot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
when:
|
||||
- not systemd
|
||||
- (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
|
||||
- pause: seconds=30
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
# following tasks are workaround for missing ansible systemd-user support
|
||||
- name: get systemd unit status
|
||||
shell: systemctl --user status urlbug.slice
|
||||
register: systemd_unit_status
|
||||
|
||||
- debug: var=systemd_unit_status
|
||||
- debug: msg="{{'{{item}}.service' not in systemd_unit_status.stdout}}"
|
||||
with_items:
|
||||
- idlebot
|
||||
- urlbot
|
||||
|
||||
- name: bots started
|
||||
shell: "systemctl --user start urlbug@{{item}}.service && sleep 20"
|
||||
with_items:
|
||||
- idlebot
|
||||
- urlbot
|
||||
when: systemd and '{{item}}.service' not in systemd_unit_status.stdout
|
||||
register: started_bots
|
||||
|
||||
- debug: var=started_bots
|
||||
|
||||
- name: bots restarted
|
||||
shell: "systemctl --user restart urlbug@{{item}}.service && sleep 10"
|
||||
with_items:
|
||||
- idlebot
|
||||
- urlbot
|
||||
when:
|
||||
- systemd
|
||||
- source_code.changed or urlbot_config.changed
|
||||
|
||||
- pause: seconds=20
|
||||
when:
|
||||
- not systemd
|
||||
- (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
|
||||
- name: urlbot started
|
||||
supervisorctl: name=bot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
when:
|
||||
- not systemd
|
||||
- (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
||||
|
||||
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
|
||||
@@ -15,6 +15,7 @@ import config
|
||||
from common import VERSION
|
||||
from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT
|
||||
from plugin_system import pluginfunction, ptypes, plugin_storage, plugin_enabled_get, plugin_enabled_set
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -92,7 +93,6 @@ def command_plugin_activation(argv, **args):
|
||||
|
||||
@pluginfunction('list', 'list plugin and parser status', ptypes.COMMAND)
|
||||
def command_list(argv, **args):
|
||||
|
||||
log.info('list plugin called')
|
||||
|
||||
if 'enabled' in argv and 'disabled' in argv:
|
||||
@@ -282,15 +282,41 @@ def command_dice(argv, **args):
|
||||
@pluginfunction('choose', 'chooses randomly between arguments', ptypes.COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
||||
def command_choose(argv, **args):
|
||||
alternatives = argv
|
||||
binary = ['Yes', 'No', 'Maybe']
|
||||
|
||||
# single or no choice
|
||||
if len(alternatives) < 2:
|
||||
return {
|
||||
'msg': '{}: {}.'.format(args['reply_user'], random.choice(['Yes', 'No']))
|
||||
'msg': '{}: {}.'.format(args['reply_user'], random.choice(binary))
|
||||
}
|
||||
elif 'choose' not in alternatives:
|
||||
choice = random.choice(alternatives)
|
||||
return {
|
||||
'msg': '%s: I prefer %s!' % (args['reply_user'], choice)
|
||||
}
|
||||
|
||||
choice = random.choice(alternatives)
|
||||
log.info('sent random choice')
|
||||
def choose_between(options):
|
||||
responses = []
|
||||
current_choices = []
|
||||
|
||||
for item in options:
|
||||
if item == 'choose':
|
||||
if len(current_choices) < 2:
|
||||
responses.append(random.choice(binary))
|
||||
else:
|
||||
responses.append(random.choice(current_choices))
|
||||
current_choices = []
|
||||
else:
|
||||
current_choices.append(item)
|
||||
if len(current_choices) < 2:
|
||||
responses.append(random.choice(binary))
|
||||
else:
|
||||
responses.append(random.choice(current_choices))
|
||||
return responses
|
||||
|
||||
log.info('sent multiple random choices')
|
||||
return {
|
||||
'msg': '%s: I prefer %s!' % (args['reply_user'], choice)
|
||||
'msg': '%s: My choices are: %s!' % (args['reply_user'], ', '.join(choose_between(alternatives)))
|
||||
}
|
||||
|
||||
|
||||
@@ -564,8 +590,8 @@ def command_dsa_watcher(argv=None, **_):
|
||||
for dsa_about in reversed(dsa_about_list):
|
||||
dsa_id = get_id_from_about_string(dsa_about)
|
||||
title = xmldoc.xpath(
|
||||
'//purl:item[@rdf:about="{}"]/purl:title/text()'.format(dsa_about),
|
||||
namespaces=nsmap
|
||||
'//purl:item[@rdf:about="{}"]/purl:title/text()'.format(dsa_about),
|
||||
namespaces=nsmap
|
||||
)[0]
|
||||
if after and dsa_id <= after:
|
||||
continue
|
||||
@@ -621,8 +647,9 @@ def remove_from_botlist(argv, **args):
|
||||
return False
|
||||
|
||||
|
||||
@pluginfunction("add-to-botlist", "add a user to the botlist", ptypes.COMMAND)
|
||||
@pluginfunction("add-to-botlist", "add a user to the botlist", ptypes.COMMAND, enabled=False)
|
||||
def add_to_botlist(argv, **args):
|
||||
return {'msg': 'feature disabled until channel separation'}
|
||||
if not argv:
|
||||
return {'msg': "wrong number of arguments!"}
|
||||
suspect = argv[0]
|
||||
@@ -776,9 +803,10 @@ def raise_an_error(argv, **args):
|
||||
|
||||
@pluginfunction('repeat', 'repeat the last message', ptypes.COMMAND)
|
||||
def repeat_message(argv, **args):
|
||||
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)
|
||||
|
||||
@@ -17,7 +17,7 @@ comment_joins_strings = [
|
||||
def comment_joins(**args):
|
||||
# max elapsed time between the latest and the N latest join
|
||||
timespan = 120
|
||||
max_joins = config.runtime_config_store
|
||||
max_joins = 6
|
||||
|
||||
current_timestamp = int(time.time())
|
||||
|
||||
|
||||
@@ -122,8 +122,10 @@ def parse_slash_me(**args):
|
||||
}
|
||||
|
||||
|
||||
@pluginfunction("recognize_bots", "got ya", ptypes.PARSE)
|
||||
@pluginfunction("recognize_bots", "got ya", ptypes.PARSE, enabled=False)
|
||||
def recognize_bots(**args):
|
||||
# disabled until channel separation
|
||||
return
|
||||
unique_standard_phrases = (
|
||||
'independent bot and have nothing to do with other artificial intelligence systems',
|
||||
'new Debian Security Announce',
|
||||
@@ -184,3 +186,10 @@ def resolve_url_title(**args):
|
||||
'msg': out
|
||||
}
|
||||
|
||||
|
||||
@pluginfunction('doctor', 'parse doctor', ptypes.PARSE, ratelimit_class=RATE_FUN | RATE_GLOBAL)
|
||||
def parse_doctor(**args):
|
||||
if 'doctor' in args['data'].lower() or 'doktor' in args['data'].lower():
|
||||
return {
|
||||
'msg': 'ELIMINIEREN! ELIMINIEREN!'
|
||||
}
|
||||
|
||||
@@ -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