1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

conf foo, setting the jid to sth with the botclass, presence support (doesn't work in MUC)

This commit is contained in:
Thorsten
2015-11-28 13:11:22 +01:00
parent 88d43f9df1
commit 277f4564a2
4 changed files with 40 additions and 16 deletions

View File

@@ -44,6 +44,16 @@ def conf_load():
return {} return {}
def conf_set(key, value):
blob = conf_load()
blob[key] = value
conf_save(blob)
def conf_get(key):
blob = conf_load()
return blob.get(key)
Bucket = namedtuple("BucketConfig", ["history", "period", "max_hist_len"]) Bucket = namedtuple("BucketConfig", ["history", "period", "max_hist_len"])
buckets = { buckets = {

View File

@@ -2,9 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import logging import logging
import time import time
import sys import sys
from common import VERSION, EVENTLOOP_DELAY, conf_load from common import VERSION, EVENTLOOP_DELAY, conf_load
try: try:
@@ -18,8 +16,7 @@ except ImportError:
sys.argv[0], sys.argv[0],
' ' * len(sys.argv[0]), ' ' * len(sys.argv[0]),
' ' * len(sys.argv[0]) ' ' * len(sys.argv[0])
) ))
)
sys.exit(1) sys.exit(1)
from sleekxmpp import ClientXMPP from sleekxmpp import ClientXMPP
@@ -36,12 +33,15 @@ class IdleBot(ClientXMPP):
self.add_event_handler('session_start', self.session_start) self.add_event_handler('session_start', self.session_start)
self.add_event_handler('groupchat_message', self.muc_message) self.add_event_handler('groupchat_message', self.muc_message)
self.priority = 0
self.status = None
self.show = None
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
def session_start(self, _): def session_start(self, _):
self.get_roster() self.get_roster()
self.send_presence() self.send_presence(ppriority=self.priority, pstatus=self.status, pshow=self.show)
for room in self.rooms: for room in self.rooms:
self.logger.info('%s: joining' % room) self.logger.info('%s: joining' % room)
@@ -83,8 +83,11 @@ def start(botclass, active=False):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.info(VERSION) logger.info(VERSION)
jid = conf('jid')
if '/' not in jid:
jid = '%s/%s' % (jid, botclass.__name__)
bot = botclass( bot = botclass(
jid=conf('jid'), jid=jid,
password=conf('password'), password=conf('password'),
rooms=conf('rooms'), rooms=conf('rooms'),
nick=conf('bot_user') nick=conf('bot_user')

View File

@@ -983,21 +983,21 @@ def recognize_bots(**args):
} }
@pluginfunction("set_status", "", ptypes_COMMAND) @pluginfunction("set_status", "set bot status", ptypes_COMMAND)
def set_status(argv, **args): def set_status(argv, **args):
if 'set_status' != argv[0]: if 'set_status' != argv[0]:
return return
if argv[1] == 'mute' and args['reply_user'] == conf('bot_owner'): if argv[1] == 'mute' and args['reply_user'] == conf('bot_owner'):
return { return {
'presence': { 'presence': {
'status': 'AWAY', 'status': 'xa',
'message': 'I\'m muted now. You can unmute me with "%s: set_status unmute"' % conf("bot_user") 'message': 'I\'m muted now. You can unmute me with "%s: set_status unmute"' % conf("bot_user")
} }
} }
elif argv[1] == 'unmute' and args['reply_user'] == conf('bot_owner'): elif argv[1] == 'unmute' and args['reply_user'] == conf('bot_owner'):
return { return {
'presence': { 'presence': {
'status': 'ONLINE', 'status': None,
'message': '' 'message': ''
} }
} }

View File

@@ -15,7 +15,7 @@ from common import (
RATE_EVENT, RATE_EVENT,
# rate_limited, # rate_limited,
rate_limit, rate_limit,
RATE_URL) RATE_URL, conf_set)
from idlebot import IdleBot, start from idlebot import IdleBot, start
from plugins import ( from plugins import (
plugins as plugin_storage, plugins as plugin_storage,
@@ -49,6 +49,7 @@ class UrlBot(IdleBot):
self.hist_flag = {p: True for p in rate_limit_classes} self.hist_flag = {p: True for p in rate_limit_classes}
self.add_event_handler('message', self.message) self.add_event_handler('message', self.message)
self.priority = 100
for r in self.rooms: for r in self.rooms:
self.add_event_handler('muc::%s::got_online' % r, self.muc_online) self.add_event_handler('muc::%s::got_online' % r, self.muc_online)
@@ -317,15 +318,15 @@ class UrlBot(IdleBot):
if ret: if ret:
self._run_action(ret, plugin, msg_obj) self._run_action(ret, plugin, msg_obj)
def _run_action(self, plugin_action, plugin, msg_obj): def _run_action(self, action, plugin, msg_obj):
""" """
Execute the plugin's execution plan Execute the plugin's execution plan
:param plugin_action: dict with event and/or msg :param action: dict with event and/or msg
:param plugin: plugin obj :param plugin: plugin obj
:param msg_obj: xmpp message obj :param msg_obj: xmpp message obj
""" """
if 'event' in plugin_action: if 'event' in action:
event = plugin_action["event"] event = action["event"]
if 'msg' in event: if 'msg' in event:
register_event(event["time"], self.send_reply, [event['msg']]) register_event(event["time"], self.send_reply, [event['msg']])
elif 'command' in event: elif 'command' in event:
@@ -333,8 +334,18 @@ class UrlBot(IdleBot):
if rate_limit(RATE_EVENT): if rate_limit(RATE_EVENT):
register_event(event["time"], command[0], command[1]) register_event(event["time"], command[0], command[1])
if 'msg' in plugin_action and rate_limit(RATE_CHAT | plugin.ratelimit_class): if 'msg' in action and rate_limit(RATE_CHAT | plugin.ratelimit_class):
self.send_reply(plugin_action['msg'], msg_obj) self.send_reply(action['msg'], msg_obj)
if 'presence' in action:
presence = action['presence']
conf_set('presence', presence)
self.status = presence['msg']
self.show = presence['status']
self.send_presence(pstatus=presence['msg'], pshow=presence['status'])
# self.reconnect(wait=True)
if '__main__' == __name__: if '__main__' == __name__:
start(UrlBot, True) start(UrlBot, True)