mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
parse plugins now usable again (command to come)
This commit is contained in:
57
plugins.py
57
plugins.py
@@ -20,6 +20,7 @@ joblist = []
|
|||||||
plugins = {p : [] for p in ptypes}
|
plugins = {p : [] for p in ptypes}
|
||||||
|
|
||||||
def pluginfunction(name, desc, plugin_type, ratelimit_class = RATE_GLOBAL, enabled = True):
|
def pluginfunction(name, desc, plugin_type, ratelimit_class = RATE_GLOBAL, enabled = True):
|
||||||
|
""" A decorator to make a plugin out of a function """
|
||||||
if plugin_type not in ptypes:
|
if plugin_type not in ptypes:
|
||||||
raise TypeError("Illegal plugin_type: %s" % plugin_type)
|
raise TypeError("Illegal plugin_type: %s" % plugin_type)
|
||||||
|
|
||||||
@@ -37,14 +38,7 @@ def register_event(t, callback, args):
|
|||||||
joblist.append((t, callback, args))
|
joblist.append((t, callback, args))
|
||||||
|
|
||||||
@pluginfunction("mental_ill", "parse mental illness", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
@pluginfunction("mental_ill", "parse mental illness", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
||||||
def parse_mental_ill(args):
|
def parse_mental_ill(**args):
|
||||||
if 'register' == args:
|
|
||||||
return {
|
|
||||||
'name': 'parse mental illness',
|
|
||||||
'args': ('data', 'reply_user'),
|
|
||||||
'ratelimit_class': RATE_NO_SILENCE | RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
min_ill = 3
|
min_ill = 3
|
||||||
c = 0
|
c = 0
|
||||||
flag = False
|
flag = False
|
||||||
@@ -66,14 +60,7 @@ def parse_mental_ill(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("debbug", "parse Debian bug numbers", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
@pluginfunction("debbug", "parse Debian bug numbers", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
||||||
def parse_debbug(args):
|
def parse_debbug(**args):
|
||||||
if 'register' == args:
|
|
||||||
return {
|
|
||||||
'name': 'parse Debian bug numbers',
|
|
||||||
'args': ('data',),
|
|
||||||
'ratelimit_class': RATE_NO_SILENCE | RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
bugs = re.findall(r'#(\d{4,})', args['data'])
|
bugs = re.findall(r'#(\d{4,})', args['data'])
|
||||||
if not bugs:
|
if not bugs:
|
||||||
return None
|
return None
|
||||||
@@ -94,14 +81,7 @@ def parse_debbug(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("cve", "parse a CVE handle", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
@pluginfunction("cve", "parse a CVE handle", ptypes.PARSE, ratelimit_class = RATE_NO_SILENCE | RATE_GLOBAL)
|
||||||
def parse_cve(args):
|
def parse_cve(**args):
|
||||||
if 'register' == args:
|
|
||||||
return {
|
|
||||||
'name': 'parse a CVE handle',
|
|
||||||
'args': ('data',),
|
|
||||||
'ratelimit_class': RATE_NO_SILENCE | RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
cves = re.findall(r'(CVE-\d\d\d\d-\d+)', args['data'].upper())
|
cves = re.findall(r'(CVE-\d\d\d\d-\d+)', args['data'].upper())
|
||||||
if not cves:
|
if not cves:
|
||||||
return None
|
return None
|
||||||
@@ -112,14 +92,7 @@ def parse_cve(args):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@pluginfunction("skynet", "parse skynet", ptypes.PARSE)
|
@pluginfunction("skynet", "parse skynet", ptypes.PARSE)
|
||||||
def parse_skynet(args):
|
def parse_skynet(**args):
|
||||||
if 'register' == args:
|
|
||||||
return {
|
|
||||||
'name': 'parse skynet',
|
|
||||||
'args': ('data',),
|
|
||||||
'ratelimit_class': RATE_GLOBAL
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'skynet' in args['data'].lower():
|
if 'skynet' in args['data'].lower():
|
||||||
logger('plugin', 'sent skynet reply')
|
logger('plugin', 'sent skynet reply')
|
||||||
return {
|
return {
|
||||||
@@ -130,25 +103,11 @@ def data_parse_other(msg_obj):
|
|||||||
data = msg_obj['body']
|
data = msg_obj['body']
|
||||||
reply_user = msg_obj['mucnick']
|
reply_user = msg_obj['mucnick']
|
||||||
|
|
||||||
for p in plugins['parse']:
|
for p in plugins[ptypes.PARSE]:
|
||||||
if ratelimit_exceeded(p['ratelimit_class']):
|
if ratelimit_exceeded(p.ratelimit_class):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
args = {}
|
ret = p(reply_user=reply_user, data=data)
|
||||||
|
|
||||||
if 'args' in list(p.keys()):
|
|
||||||
for a in p['args']:
|
|
||||||
if None == a:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if 'data' == a:
|
|
||||||
args['data'] = data
|
|
||||||
elif 'reply_user' == a:
|
|
||||||
args['reply_user'] = reply_user
|
|
||||||
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