mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
patch by braph: refactor muc_online events into own plugin class
This commit is contained in:
@@ -5,8 +5,8 @@ import traceback
|
||||
import types
|
||||
|
||||
import config
|
||||
from common import RATE_NO_LIMIT, pluginfunction, ptypes_PARSE, ptypes_COMMAND, ptypes
|
||||
from plugins import commands, parsers
|
||||
from common import RATE_NO_LIMIT, pluginfunction, ptypes_PARSE, ptypes_COMMAND, ptypes_MUC_ONLINE, ptypes
|
||||
from plugins import commands, parsers, muc_online
|
||||
|
||||
joblist = []
|
||||
plugins = {p: [] for p in ptypes}
|
||||
@@ -77,6 +77,8 @@ def register(func_type):
|
||||
plugin_funcs = list(commands.__dict__.values()) + local_commands
|
||||
elif func_type == ptypes_PARSE:
|
||||
plugin_funcs = parsers.__dict__.values()
|
||||
elif func_type == ptypes_MUC_ONLINE:
|
||||
plugin_funcs = muc_online.__dict__.values()
|
||||
else:
|
||||
raise RuntimeError("invalid func type: {}".format(func_type))
|
||||
|
||||
@@ -107,6 +109,7 @@ def register_plugin(function, func_type):
|
||||
def register_all():
|
||||
register(ptypes_PARSE)
|
||||
register(ptypes_COMMAND)
|
||||
register(ptypes_MUC_ONLINE)
|
||||
|
||||
|
||||
def event_trigger():
|
||||
|
||||
45
plugins/muc_online.py
Normal file
45
plugins/muc_online.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import logging
|
||||
|
||||
import config
|
||||
from common import (
|
||||
pluginfunction,
|
||||
ptypes_MUC_ONLINE
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@pluginfunction('send_record', 'delivers previously saved message to user', ptypes_MUC_ONLINE)
|
||||
def send_record(**args):
|
||||
arg_user = args['reply_user']
|
||||
arg_user_key = arg_user.lower()
|
||||
user_records = config.runtimeconf_get('user_records')
|
||||
|
||||
if arg_user_key in user_records:
|
||||
records = user_records[arg_user_key]
|
||||
|
||||
if not records:
|
||||
return None
|
||||
|
||||
response = {
|
||||
'msg': '%s, there %s %d message%s for you:\n%s' % (
|
||||
arg_user,
|
||||
'is' if len(records) == 1 else 'are',
|
||||
len(records),
|
||||
'' if len(records) == 1 else 's',
|
||||
'\n'.join(records)
|
||||
)
|
||||
}
|
||||
|
||||
if config.conf_get('persistent_locked'):
|
||||
log.warning("couldn't get exclusive lock")
|
||||
return None
|
||||
|
||||
config.conf_set('persistent_locked', True)
|
||||
|
||||
user_records.pop(arg_user_key)
|
||||
config.runtimeconf_persist()
|
||||
|
||||
config.conf_set('persistent_locked', False)
|
||||
|
||||
return response
|
||||
Reference in New Issue
Block a user