Compare commits
10 Commits
fa9e970eeb
...
d9d87f114a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9d87f114a | ||
|
|
4541dd0ebb | ||
|
|
efd18525bb | ||
|
|
dff83acaf6 | ||
|
|
94c78335fb | ||
|
|
d5886fbd94 | ||
|
|
f7ab2cfbdd | ||
|
|
5b9ed2ef94 | ||
|
|
5ffa3f0dc7 | ||
|
|
1c0f7a7024 |
@@ -20,6 +20,7 @@
|
|||||||
vars:
|
vars:
|
||||||
- botrepo: http://aero2k.de/t/repos/urlbot-native.git
|
- botrepo: http://aero2k.de/t/repos/urlbot-native.git
|
||||||
- pypi_mirror: http://pypi.fcio.net/simple/
|
- pypi_mirror: http://pypi.fcio.net/simple/
|
||||||
|
- systemd: true
|
||||||
tasks:
|
tasks:
|
||||||
- include_vars: credentials.yml
|
- include_vars: credentials.yml
|
||||||
tags: [render_config]
|
tags: [render_config]
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
shell: virtualenv -p python3 --system-site-packages ~/botenv creates=~/botenv/bin/activate
|
shell: virtualenv -p python3 --system-site-packages ~/botenv creates=~/botenv/bin/activate
|
||||||
- name: virtualenv for supervisord
|
- name: virtualenv for supervisord
|
||||||
shell: virtualenv -p python2 ~/svenv creates=~/svenv/bin/activate
|
shell: virtualenv -p python2 ~/svenv creates=~/svenv/bin/activate
|
||||||
|
when: not systemd
|
||||||
- name: clone repository
|
- name: clone repository
|
||||||
git: repo="{{botrepo}}" dest=~/urlbot force=yes update=yes
|
git: repo="{{botrepo}}" dest=~/urlbot force=yes update=yes
|
||||||
register: source_code
|
register: source_code
|
||||||
@@ -34,6 +36,7 @@
|
|||||||
pip: requirements="~/urlbot/requirements.txt" virtualenv=~/botenv extra_args="-i {{pypi_mirror}}"
|
pip: requirements="~/urlbot/requirements.txt" virtualenv=~/botenv extra_args="-i {{pypi_mirror}}"
|
||||||
- name: install supervisor
|
- name: install supervisor
|
||||||
pip: name=supervisor virtualenv=~/svenv extra_args="-i {{pypi_mirror}}"
|
pip: name=supervisor virtualenv=~/svenv extra_args="-i {{pypi_mirror}}"
|
||||||
|
when: not systemd
|
||||||
|
|
||||||
- name: set configuration
|
- name: set configuration
|
||||||
lineinfile: dest=~/urlbot/local_config.ini create=yes line="{{item.key}} = {{item.value}}" regexp="^{{item.key}}.="
|
lineinfile: dest=~/urlbot/local_config.ini create=yes line="{{item.key}} = {{item.value}}" regexp="^{{item.key}}.="
|
||||||
@@ -60,29 +63,94 @@
|
|||||||
- name: create supervisor config
|
- name: create supervisor config
|
||||||
copy: src=supervisord.conf dest=~/supervisord.conf
|
copy: src=supervisord.conf dest=~/supervisord.conf
|
||||||
register: supervisord
|
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
|
- name: verify supervisor running
|
||||||
shell: nc -z 127.0.0.1 9004; echo $? executable=/bin/bash
|
shell: nc -z 127.0.0.1 9004; echo $? executable=/bin/bash
|
||||||
register: supervisor_running
|
register: supervisor_running
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
when: not systemd
|
||||||
|
|
||||||
- name: start supervisord
|
- name: start supervisord
|
||||||
shell: source ~/svenv/bin/activate && supervisord executable=/bin/bash
|
shell: source ~/svenv/bin/activate && supervisord executable=/bin/bash
|
||||||
register: start_supervisor
|
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"
|
#changed_when: "'already listening' not in start_supervisor.stdout"
|
||||||
|
|
||||||
- name: activate supervisord changes
|
- name: activate supervisord changes
|
||||||
when: supervisord.changed
|
|
||||||
shell: source ~/svenv/bin/activate && supervisorctl reload executable=/bin/bash
|
shell: source ~/svenv/bin/activate && supervisorctl reload executable=/bin/bash
|
||||||
|
when:
|
||||||
|
- not systemd
|
||||||
|
- supervisord.changed
|
||||||
|
|
||||||
- name: idlebot started
|
- name: idlebot started
|
||||||
supervisorctl: name=idlebot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
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
|
# following tasks are workaround for missing ansible systemd-user support
|
||||||
when: (source_code.changed or urlbot_config.changed) and not supervisord.changed
|
- 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
|
- name: urlbot started
|
||||||
supervisorctl: name=bot state=restarted supervisorctl_path=~/svenv/bin/supervisorctl
|
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 common import VERSION
|
||||||
from rate_limit import RATE_FUN, RATE_GLOBAL, RATE_INTERACTIVE, RATE_NO_SILENCE, RATE_NO_LIMIT
|
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
|
from plugin_system import pluginfunction, ptypes, plugin_storage, plugin_enabled_get, plugin_enabled_set
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -92,7 +93,6 @@ def command_plugin_activation(argv, **args):
|
|||||||
|
|
||||||
@pluginfunction('list', 'list plugin and parser status', ptypes.COMMAND)
|
@pluginfunction('list', 'list plugin and parser status', ptypes.COMMAND)
|
||||||
def command_list(argv, **args):
|
def command_list(argv, **args):
|
||||||
|
|
||||||
log.info('list plugin called')
|
log.info('list plugin called')
|
||||||
|
|
||||||
if 'enabled' in argv and 'disabled' in argv:
|
if 'enabled' in argv and 'disabled' in argv:
|
||||||
@@ -282,17 +282,43 @@ def command_dice(argv, **args):
|
|||||||
@pluginfunction('choose', 'chooses randomly between arguments', ptypes.COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
@pluginfunction('choose', 'chooses randomly between arguments', ptypes.COMMAND, ratelimit_class=RATE_INTERACTIVE)
|
||||||
def command_choose(argv, **args):
|
def command_choose(argv, **args):
|
||||||
alternatives = argv
|
alternatives = argv
|
||||||
|
binary = ['Yes', 'No', 'Maybe']
|
||||||
|
|
||||||
|
# single or no choice
|
||||||
if len(alternatives) < 2:
|
if len(alternatives) < 2:
|
||||||
return {
|
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)
|
choice = random.choice(alternatives)
|
||||||
log.info('sent random choice')
|
|
||||||
return {
|
return {
|
||||||
'msg': '%s: I prefer %s!' % (args['reply_user'], choice)
|
'msg': '%s: I prefer %s!' % (args['reply_user'], 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: My choices are: %s!' % (args['reply_user'], ', '.join(choose_between(alternatives)))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@pluginfunction('teatimer', 'sets a tea timer to $1 or currently %d seconds' % config.conf_get('tea_steep_time'),
|
@pluginfunction('teatimer', 'sets a tea timer to $1 or currently %d seconds' % config.conf_get('tea_steep_time'),
|
||||||
ptypes.COMMAND)
|
ptypes.COMMAND)
|
||||||
@@ -621,8 +647,9 @@ def remove_from_botlist(argv, **args):
|
|||||||
return False
|
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):
|
def add_to_botlist(argv, **args):
|
||||||
|
return {'msg': 'feature disabled until channel separation'}
|
||||||
if not argv:
|
if not argv:
|
||||||
return {'msg': "wrong number of arguments!"}
|
return {'msg': "wrong number of arguments!"}
|
||||||
suspect = argv[0]
|
suspect = argv[0]
|
||||||
@@ -776,6 +803,7 @@ def raise_an_error(argv, **args):
|
|||||||
|
|
||||||
@pluginfunction('repeat', 'repeat the last message', ptypes.COMMAND)
|
@pluginfunction('repeat', 'repeat the last message', ptypes.COMMAND)
|
||||||
def repeat_message(argv, **args):
|
def repeat_message(argv, **args):
|
||||||
|
if args['stack']:
|
||||||
return {
|
return {
|
||||||
'msg': args['stack'][-1]['body']
|
'msg': args['stack'][-1]['body']
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ comment_joins_strings = [
|
|||||||
def comment_joins(**args):
|
def comment_joins(**args):
|
||||||
# max elapsed time between the latest and the N latest join
|
# max elapsed time between the latest and the N latest join
|
||||||
timespan = 120
|
timespan = 120
|
||||||
max_joins = config.runtime_config_store
|
max_joins = 6
|
||||||
|
|
||||||
current_timestamp = int(time.time())
|
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):
|
def recognize_bots(**args):
|
||||||
|
# disabled until channel separation
|
||||||
|
return
|
||||||
unique_standard_phrases = (
|
unique_standard_phrases = (
|
||||||
'independent bot and have nothing to do with other artificial intelligence systems',
|
'independent bot and have nothing to do with other artificial intelligence systems',
|
||||||
'new Debian Security Announce',
|
'new Debian Security Announce',
|
||||||
@@ -184,3 +186,10 @@ def resolve_url_title(**args):
|
|||||||
'msg': out
|
'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:
|
if not api_key:
|
||||||
return
|
return
|
||||||
message_stack = args['stack']
|
message_stack = args['stack']
|
||||||
|
if not message_stack[-1]:
|
||||||
|
return
|
||||||
last_message = message_stack[-1]['body']
|
last_message = message_stack[-1]['body']
|
||||||
data = {
|
data = {
|
||||||
'q': last_message,
|
'q': last_message,
|
||||||
|
|||||||
11
urlbot.py
11
urlbot.py
@@ -7,6 +7,8 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
from collections import deque
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -34,7 +36,7 @@ class UrlBot(IdleBot):
|
|||||||
|
|
||||||
self.hist_ts = {p: [] for p in rate_limit_classes}
|
self.hist_ts = {p: [] for p in rate_limit_classes}
|
||||||
self.hist_flag = {p: True 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.add_event_handler('message', self.message)
|
||||||
self.priority = 100
|
self.priority = 100
|
||||||
@@ -196,9 +198,8 @@ class UrlBot(IdleBot):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
finally:
|
finally:
|
||||||
if len(self.message_stack) > 4:
|
if msg_obj['from'].bare in self.rooms:
|
||||||
self.message_stack.pop(0)
|
self.message_stack[msg_obj['from'].bare].append(msg_obj)
|
||||||
self.message_stack.append(msg_obj)
|
|
||||||
|
|
||||||
def handle_muc_online(self, msg_obj):
|
def handle_muc_online(self, msg_obj):
|
||||||
"""
|
"""
|
||||||
@@ -268,7 +269,7 @@ class UrlBot(IdleBot):
|
|||||||
reply_user=reply_user,
|
reply_user=reply_user,
|
||||||
msg_obj=msg_obj,
|
msg_obj=msg_obj,
|
||||||
argv=words[2:] if len(words) > 1 else [],
|
argv=words[2:] if len(words) > 1 else [],
|
||||||
stack=self.message_stack
|
stack=self.message_stack.get(msg_obj['from'].bare, [])
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret:
|
if ret:
|
||||||
|
|||||||
Reference in New Issue
Block a user