mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
finsih major rework of plugin.py
* We can give any number of arguments to command plugins * now the pluginfunction decorator is used instead args == "register" * wp plugin now joins arguments with whitespaces
This commit is contained in:
366
plugins.py
366
plugins.py
@@ -12,6 +12,7 @@ from local_config import conf, set_conf
|
|||||||
from common import *
|
from common import *
|
||||||
from urlbot import extract_title
|
from urlbot import extract_title
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
ptypes = Enum("plugin_types", "PARSE COMMAND")
|
ptypes = Enum("plugin_types", "PARSE COMMAND")
|
||||||
|
|
||||||
@@ -115,18 +116,9 @@ def data_parse_other(msg_obj):
|
|||||||
send_reply(ret['msg'], msg_obj)
|
send_reply(ret['msg'], msg_obj)
|
||||||
|
|
||||||
@pluginfunction("help", "print help for a command or all known commands", ptypes.COMMAND)
|
@pluginfunction("help", "print help for a command or all known commands", ptypes.COMMAND)
|
||||||
def command_help(args):
|
def command_help(argv,**args):
|
||||||
if 'register' == args:
|
command = argv[0]
|
||||||
return {
|
what = argv[1] if len(argv) > 1 else None
|
||||||
'name': 'help',
|
|
||||||
'desc': 'print help for a command or all known commands',
|
|
||||||
'args': ('argv0', 'argv1', 'reply_user', 'cmd_list'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
command = args['argv0']
|
|
||||||
what = args['argv1']
|
|
||||||
|
|
||||||
if 'help' != command:
|
if 'help' != command:
|
||||||
return
|
return
|
||||||
@@ -138,33 +130,24 @@ def command_help(args):
|
|||||||
str(args['cmd_list']).strip('[]')
|
str(args['cmd_list']).strip('[]')
|
||||||
}
|
}
|
||||||
|
|
||||||
if not what in [p['name'] for p in plugins['command']]:
|
if not what in [p.plugin_name for p in plugins[ptypes.COMMAND]]:
|
||||||
logger('plugin', 'no help found for %s' % what)
|
logger('plugin', 'no help found for %s' % what)
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': no such command: %s' % what
|
'msg': args['reply_user'] + ': no such command: %s' % what
|
||||||
}
|
}
|
||||||
|
|
||||||
for p in plugins['command']:
|
for p in plugins[ptypes.COMMAND]:
|
||||||
if what == p['name']:
|
if what == p.plugin_name:
|
||||||
logger('plugin', 'sent help for %s' % what)
|
logger('plugin', 'sent help for %s' % what)
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': help for %s: %s' % (
|
'msg': args['reply_user'] + ': help for %s: %s' % (
|
||||||
what, p['desc']
|
what, p.plugin_desc
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("version", "prints version", ptypes.COMMAND)
|
@pluginfunction("version", "prints version", ptypes.COMMAND)
|
||||||
def command_version(args):
|
def command_version(argv,**args):
|
||||||
if 'register' == args:
|
if 'version' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'version',
|
|
||||||
'desc': 'prints version',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'version' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent version string')
|
logger('plugin', 'sent version string')
|
||||||
@@ -173,17 +156,8 @@ def command_version(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("klammer", "prints an anoying paper clip aka. Karl Klammer", ptypes.COMMAND)
|
@pluginfunction("klammer", "prints an anoying paper clip aka. Karl Klammer", ptypes.COMMAND)
|
||||||
def command_klammer(args):
|
def command_klammer(argv,**args):
|
||||||
if 'register' == args:
|
if 'klammer' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'klammer',
|
|
||||||
'desc': 'prints an anoying paper clip aka. Karl Klammer',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'klammer' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent karl klammer')
|
logger('plugin', 'sent karl klammer')
|
||||||
@@ -200,17 +174,8 @@ def command_klammer(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("unikot", "prints an unicode string", ptypes.COMMAND)
|
@pluginfunction("unikot", "prints an unicode string", ptypes.COMMAND)
|
||||||
def command_unicode(args):
|
def command_unicode(argv,**args):
|
||||||
if 'register' == args:
|
if 'unikot' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'unikot',
|
|
||||||
'desc': 'prints an unicode string',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'unikot' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent some unicode')
|
logger('plugin', 'sent some unicode')
|
||||||
@@ -224,17 +189,8 @@ def command_unicode(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("source", "prints git URL", ptypes.COMMAND)
|
@pluginfunction("source", "prints git URL", ptypes.COMMAND)
|
||||||
def command_source(args):
|
def command_source(argv,**args):
|
||||||
if 'register' == args:
|
if not argv[0] in ('source', 'src'):
|
||||||
return {
|
|
||||||
'name': 'source',
|
|
||||||
'desc': 'prints git URL',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if not args['argv0'] in ('source', 'src'):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent source URL')
|
logger('plugin', 'sent source URL')
|
||||||
@@ -243,27 +199,18 @@ def command_source(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("dice", "rolls a dice, optional N times", ptypes.COMMAND, ratelimit_class = RATE_INTERACTIVE)
|
@pluginfunction("dice", "rolls a dice, optional N times", ptypes.COMMAND, ratelimit_class = RATE_INTERACTIVE)
|
||||||
def command_dice(args):
|
def command_dice(argv, **args):
|
||||||
if 'register' == args:
|
if 'dice' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'dice',
|
|
||||||
'desc': 'rolls a dice, optional N times',
|
|
||||||
'args': ('argv0', 'argv1', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_INTERACTIVE
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'dice' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
count = 1 if None is args['argv1'] else int(args['argv1'])
|
count = 1 if len(argv) < 2 else int(argv[1])
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return {
|
return {
|
||||||
'msg': '%s: dice: error when parsing int(%s): %s' % (
|
'msg': '%s: dice: error when parsing int(%s): %s' % (
|
||||||
args['reply_user'], args['argv1'], str(e)
|
args['reply_user'], argv[1], str(e)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,17 +241,8 @@ def command_dice(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("uptime", "prints uptime", ptypes.COMMAND)
|
@pluginfunction("uptime", "prints uptime", ptypes.COMMAND)
|
||||||
def command_uptime(args):
|
def command_uptime(argv, **args):
|
||||||
if 'register' == args:
|
if 'uptime' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'uptime',
|
|
||||||
'desc': 'prints uptime',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'uptime' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
u = int(conf('uptime') + time.time())
|
u = int(conf('uptime') + time.time())
|
||||||
@@ -322,17 +260,8 @@ def command_uptime(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("ping", "sends pong", ptypes.COMMAND, ratelimit_class = RATE_INTERACTIVE)
|
@pluginfunction("ping", "sends pong", ptypes.COMMAND, ratelimit_class = RATE_INTERACTIVE)
|
||||||
def command_ping(args):
|
def command_ping(argv, **args):
|
||||||
if 'register' == args:
|
if 'ping' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'ping',
|
|
||||||
'desc': 'sends pong',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_INTERACTIVE
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'ping' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
rnd = random.randint(0, 3) # 1:4
|
rnd = random.randint(0, 3) # 1:4
|
||||||
@@ -351,17 +280,8 @@ def command_ping(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("info", "prints info message", ptypes.COMMAND)
|
@pluginfunction("info", "prints info message", ptypes.COMMAND)
|
||||||
def command_info(args):
|
def command_info(argv,**args):
|
||||||
if 'register' == args:
|
if 'info' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'info',
|
|
||||||
'desc': 'prints info message',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'info' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent long info')
|
logger('plugin', 'sent long info')
|
||||||
@@ -370,28 +290,19 @@ def command_info(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("teatimer", 'sets a tea timer to $1 or currently %d seconds' % conf('tea_steep_time'), ptypes.COMMAND)
|
@pluginfunction("teatimer", 'sets a tea timer to $1 or currently %d seconds' % conf('tea_steep_time'), ptypes.COMMAND)
|
||||||
def command_teatimer(args):
|
def command_teatimer(argv,**args):
|
||||||
if 'register' == args:
|
if 'teatimer' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'teatimer',
|
|
||||||
'desc': 'sets a tea timer to $1 or currently %d seconds' % conf('tea_steep_time'),
|
|
||||||
'args': ('reply_user', 'msg_obj', 'argv0', 'argv1'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'teatimer' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
steep = conf('tea_steep_time')
|
steep = conf('tea_steep_time')
|
||||||
|
|
||||||
if None != args['argv1']:
|
if len(argv) > 1:
|
||||||
try:
|
try:
|
||||||
steep = int(args['argv1'])
|
steep = int(argv[1])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': error when parsing int(%s): %s' % (
|
'msg': args['reply_user'] + ': error when parsing int(%s): %s' % (
|
||||||
args['argv1'], str(e)
|
argv[1], str(e)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,25 +326,16 @@ def command_teatimer(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("decode", "prints the long description of an unicode character", ptypes.COMMAND)
|
@pluginfunction("decode", "prints the long description of an unicode character", ptypes.COMMAND)
|
||||||
def command_decode(args):
|
def command_decode(argv,**args):
|
||||||
if 'register' == args:
|
if 'decode' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'decode',
|
|
||||||
'desc': 'prints the long description of an unicode character',
|
|
||||||
'args': ('argv0', 'argv1', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'decode' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if None == args['argv1']:
|
if len(argv) < 1:
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': usage: decode {single character}'
|
'msg': args['reply_user'] + ': usage: decode {single character}'
|
||||||
}
|
}
|
||||||
|
|
||||||
char = args['argv1']
|
char = argv[1]
|
||||||
char_esc = str(char.encode('unicode_escape'))[3:-1]
|
char_esc = str(char.encode('unicode_escape'))[3:-1]
|
||||||
logger('plugin', 'decode called for %s' % char)
|
logger('plugin', 'decode called for %s' % char)
|
||||||
|
|
||||||
@@ -450,37 +352,30 @@ def command_decode(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("show-blacklist", "show the current URL blacklist, optionally filtered", ptypes.COMMAND)
|
@pluginfunction("show-blacklist", "show the current URL blacklist, optionally filtered", ptypes.COMMAND)
|
||||||
def command_show_blacklist(args):
|
def command_show_blacklist(argv,**args):
|
||||||
if 'register' == args:
|
if 'show-blacklist' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'show-blacklist',
|
|
||||||
'desc': 'show the current URL blacklist, optionally filtered',
|
|
||||||
'args': ('argv0', 'reply_user', 'argv1'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'show-blacklist' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'sent URL blacklist')
|
logger('plugin', 'sent URL blacklist')
|
||||||
|
|
||||||
|
argv1 = None if len(argv) < 2 else argv[1]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'msg': [
|
'msg': [
|
||||||
args['reply_user'] + ': URL blacklist%s: ' % (
|
args['reply_user'] + ': URL blacklist%s: ' % (
|
||||||
'' if not args['argv1'] else ' (limited to %s)' % args['argv1']
|
'' if not argv1 else ' (limited to %s)' % argv1
|
||||||
)
|
)
|
||||||
] + [
|
] + [
|
||||||
b for b in conf('url_blacklist')
|
b for b in conf('url_blacklist')
|
||||||
if not args['argv1'] or args['argv1'] in b
|
if not argv1 or argv1 in b
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
def usersetting_get(args):
|
def usersetting_get(argv,args):
|
||||||
blob = conf_load()
|
blob = conf_load()
|
||||||
|
|
||||||
arg_user = args['reply_user']
|
arg_user = args['reply_user']
|
||||||
arg_key = args['argv1']
|
arg_key = argv[1]
|
||||||
|
|
||||||
if not arg_user in blob['user_pref']:
|
if not arg_user in blob['user_pref']:
|
||||||
return {
|
return {
|
||||||
@@ -495,23 +390,14 @@ def usersetting_get(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("set", "modify a user setting", ptypes.COMMAND)
|
@pluginfunction("set", "modify a user setting", ptypes.COMMAND)
|
||||||
def command_usersetting(args):
|
def command_usersetting(argv,**args):
|
||||||
if 'register' == args:
|
if 'set' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'set',
|
|
||||||
'desc': 'modify a user setting',
|
|
||||||
'args': ('reply_user', 'argv0', 'argv1', 'argv2', 'msg_obj'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'set' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
settings = ['spoiler']
|
settings = ['spoiler']
|
||||||
arg_user = args['reply_user']
|
arg_user = args['reply_user']
|
||||||
arg_key = args['argv1']
|
arg_key = argv[1] if len(argv) > 1 else None
|
||||||
arg_val = args['argv2']
|
arg_val = argv[2] if len(argv) > 2 else None
|
||||||
|
|
||||||
if not arg_key in settings:
|
if not arg_key in settings:
|
||||||
return {
|
return {
|
||||||
@@ -525,7 +411,7 @@ def command_usersetting(args):
|
|||||||
|
|
||||||
if None == arg_val:
|
if None == arg_val:
|
||||||
# display current value
|
# display current value
|
||||||
return usersetting_get(args)
|
return usersetting_get(argv, args)
|
||||||
|
|
||||||
if conf('persistent_locked'):
|
if conf('persistent_locked'):
|
||||||
return {
|
return {
|
||||||
@@ -546,20 +432,11 @@ def command_usersetting(args):
|
|||||||
set_conf('persistent_locked', False)
|
set_conf('persistent_locked', False)
|
||||||
|
|
||||||
# display value written to db
|
# display value written to db
|
||||||
return usersetting_get(args)
|
return usersetting_get(argv,args)
|
||||||
|
|
||||||
@pluginfunction("cake", "displays a cake ASCII art", ptypes.COMMAND)
|
@pluginfunction("cake", "displays a cake ASCII art", ptypes.COMMAND)
|
||||||
def command_cake(args):
|
def command_cake(argv, **args):
|
||||||
if 'register' == args:
|
if 'cake' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'cake',
|
|
||||||
'desc': 'displays a cake ASCII art',
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'cake' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -567,22 +444,13 @@ def command_cake(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("remember", "remembers something", ptypes.COMMAND)
|
@pluginfunction("remember", "remembers something", ptypes.COMMAND)
|
||||||
def command_remember(args):
|
def command_remember(argv,**args):
|
||||||
if 'register' == args:
|
if 'remember' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'remember',
|
|
||||||
'desc': 'remembers something',
|
|
||||||
'args': ('argv0', 'argv1', 'data', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'remember' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'remember plugin called')
|
logger('plugin', 'remember plugin called')
|
||||||
|
|
||||||
if not args['argv1']:
|
if not len(argv) > 1:
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': invalid message'
|
'msg': args['reply_user'] + ': invalid message'
|
||||||
}
|
}
|
||||||
@@ -596,17 +464,8 @@ def command_remember(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("recall", "recalls something previously 'remember'ed", ptypes.COMMAND)
|
@pluginfunction("recall", "recalls something previously 'remember'ed", ptypes.COMMAND)
|
||||||
def command_recall(args):
|
def command_recall(argv,**args):
|
||||||
if 'register' == args:
|
if 'recall' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'recall',
|
|
||||||
'desc': "recalls something previously 'remember'ed",
|
|
||||||
'args': ('argv0', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'recall' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'recall plugin called')
|
logger('plugin', 'recall plugin called')
|
||||||
@@ -615,19 +474,11 @@ def command_recall(args):
|
|||||||
'msg': args['reply_user'] + ': recalling %s' % conf('data_remember')
|
'msg': args['reply_user'] + ': recalling %s' % conf('data_remember')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#TODO: send a hint if someone types plugin as command
|
||||||
@pluginfunction("plugin", "disable' or 'enable' plugins", ptypes.COMMAND)
|
@pluginfunction("plugin", "disable' or 'enable' plugins", ptypes.COMMAND)
|
||||||
def command_plugin_activation(args):
|
def command_plugin_activation(argv,**args):
|
||||||
if 'register' == args:
|
command = argv[0]
|
||||||
return {
|
plugin = argv[1] if len(argv) > 1 else None
|
||||||
'name': 'plugin',
|
|
||||||
'desc': "'disable' or 'enable' plugins",
|
|
||||||
'args': ('argv0', 'argv1', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
command = args['argv0']
|
|
||||||
plugin = args['argv1']
|
|
||||||
|
|
||||||
if not command in ('enable', 'disable'):
|
if not command in ('enable', 'disable'):
|
||||||
return
|
return
|
||||||
@@ -638,15 +489,14 @@ def command_plugin_activation(args):
|
|||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': no plugin given'
|
'msg': args['reply_user'] + ': no plugin given'
|
||||||
}
|
}
|
||||||
elif 'plugin' == plugin:
|
elif command_plugin_activation.plugin_name == plugin:
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': not allowed'
|
'msg': args['reply_user'] + ': not allowed'
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c in enumerate(plugins['command']):
|
for c in plugins[ptypes.COMMAND]:
|
||||||
if c['name'] == plugin:
|
if c.plugin_name == plugin:
|
||||||
plugins['command'][i]['is_enabled'] = \
|
c.is_enabled = 'enable' == command
|
||||||
True if 'enable' == command else False
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'msg': args['reply_user'] + ': %sd %s' %(
|
'msg': args['reply_user'] + ': %sd %s' %(
|
||||||
@@ -659,41 +509,29 @@ def command_plugin_activation(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("wp-en", "crawl the english Wikipedia", ptypes.COMMAND)
|
@pluginfunction("wp-en", "crawl the english Wikipedia", ptypes.COMMAND)
|
||||||
def command_wp_en(args):
|
def command_wp_en(argv,**args):
|
||||||
if 'register' == args:
|
if 'wp-en' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'wp-en',
|
|
||||||
'desc': 'crawl the english Wikipedia',
|
|
||||||
'args': ('argv0', 'argv1', 'argv2', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'wp-en' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if args['argv0']:
|
if argv[0]:
|
||||||
args['argv0'] = 'wp'
|
argv[0] = 'wp'
|
||||||
|
|
||||||
return command_wp(args, lang='en')
|
return command_wp(argv, lang="en", **args)
|
||||||
|
|
||||||
@pluginfunction("wp", "crawl the german Wikipedia", ptypes.COMMAND)
|
@pluginfunction("wp", "crawl the german Wikipedia", ptypes.COMMAND)
|
||||||
def command_wp(args, lang='de'):
|
def command_wp(argv,lang="de",**args):
|
||||||
if 'register' == args:
|
if 'wp' != argv[0]:
|
||||||
return {
|
|
||||||
'name': 'wp',
|
|
||||||
'desc': 'crawl the german Wikipedia',
|
|
||||||
'args': ('argv0', 'argv1', 'argv2', 'reply_user'),
|
|
||||||
'is_enabled': True,
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'wp' != args['argv0']:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
logger('plugin', 'wp plugin called')
|
logger('plugin', 'wp plugin called')
|
||||||
|
|
||||||
query = args['argv1']
|
query = " ".join(argv[1:])
|
||||||
|
|
||||||
|
if query == "":
|
||||||
|
return {
|
||||||
|
'msg': args['reply_user'] + ": You must enter a query"
|
||||||
|
}
|
||||||
|
|
||||||
# FIXME: escaping. probably.
|
# FIXME: escaping. probably.
|
||||||
api = ('https://%s.wikipedia.org/w/api.php?action=query&prop=extracts&' + \
|
api = ('https://%s.wikipedia.org/w/api.php?action=query&prop=extracts&' + \
|
||||||
'explaintext&exsentences=2&rawcontinue=1&format=json&titles=%s') % (
|
'explaintext&exsentences=2&rawcontinue=1&format=json&titles=%s') % (
|
||||||
@@ -755,7 +593,7 @@ def command_wp(args, lang='de'):
|
|||||||
# 'ratelimit_class': RATE_GLOBAL
|
# 'ratelimit_class': RATE_GLOBAL
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# if 'dummy' != args['argv0']:
|
# if 'dummy' != argv[0]:
|
||||||
# return
|
# return
|
||||||
#
|
#
|
||||||
# logger('plugin', 'dummy plugin called')
|
# logger('plugin', 'dummy plugin called')
|
||||||
@@ -772,7 +610,7 @@ def else_command(args):
|
|||||||
|
|
||||||
def data_parse_commands(msg_obj):
|
def data_parse_commands(msg_obj):
|
||||||
data = msg_obj['body']
|
data = msg_obj['body']
|
||||||
words = data.split(' ')
|
words = data.split()
|
||||||
|
|
||||||
if 2 > len(words): # need at least two words
|
if 2 > len(words): # need at least two words
|
||||||
return None
|
return None
|
||||||
@@ -787,48 +625,20 @@ def data_parse_commands(msg_obj):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
reply_user = msg_obj['mucnick']
|
reply_user = msg_obj['mucnick']
|
||||||
(argv0, argv1, argv2) = (None, None, None)
|
|
||||||
if 1 < len(words):
|
|
||||||
argv0 = words[1]
|
|
||||||
if 2 < len(words):
|
|
||||||
argv1 = words[2]
|
|
||||||
if 3 < len(words):
|
|
||||||
argv2 = words[3]
|
|
||||||
|
|
||||||
for p in plugins['command']:
|
for p in plugins[ptypes.COMMAND]:
|
||||||
if ratelimit_exceeded(p['ratelimit_class']):
|
if ratelimit_exceeded(p.ratelimit_class):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not p['is_enabled']:
|
if not p.is_enabled:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
args = {}
|
ret = p(data = data,
|
||||||
|
cmd_list = [pl.plugin_name for pl in plugins[ptypes.COMMAND]],
|
||||||
|
reply_user = reply_user,
|
||||||
|
msg_obj = msg_obj,
|
||||||
|
argv = words[1:])
|
||||||
|
|
||||||
if 'args' in list(p.keys()):
|
|
||||||
for a in p['args']:
|
|
||||||
if None == a:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if 'data' == a:
|
|
||||||
args['data'] = data
|
|
||||||
elif 'cmd_list' == a:
|
|
||||||
cmds = [c['name'] for c in plugins['command']]
|
|
||||||
cmds.sort()
|
|
||||||
args['cmd_list'] = cmds
|
|
||||||
elif 'reply_user' == a:
|
|
||||||
args['reply_user'] = reply_user
|
|
||||||
elif 'msg_obj' == a:
|
|
||||||
args['msg_obj'] = msg_obj
|
|
||||||
elif 'argv0' == a:
|
|
||||||
args['argv0'] = argv0
|
|
||||||
elif 'argv1' == a:
|
|
||||||
args['argv1'] = argv1
|
|
||||||
elif 'argv2' == a:
|
|
||||||
args['argv2'] = argv2
|
|
||||||
else:
|
|
||||||
logger('warn', 'unknown required arg for %s: %s' % (p['name'], a))
|
|
||||||
|
|
||||||
ret = p['func'](args)
|
|
||||||
|
|
||||||
if None != ret:
|
if None != ret:
|
||||||
if 'msg' in list(ret.keys()):
|
if 'msg' in list(ret.keys()):
|
||||||
|
|||||||
Reference in New Issue
Block a user