adjustments to pass msg to data_parse_*
This commit is contained in:
27
plugins.py
27
plugins.py
@@ -16,20 +16,6 @@ plugins = {}
|
|||||||
plugins['parse'] = []
|
plugins['parse'] = []
|
||||||
plugins['command'] = []
|
plugins['command'] = []
|
||||||
|
|
||||||
def get_reply_data(data, field=0):
|
|
||||||
# FIXME: we can't determine if a user named 'foo> ' just wrote ' > bar'
|
|
||||||
# or a user 'foo' just wrote '> > bar'
|
|
||||||
f = data.split()
|
|
||||||
|
|
||||||
if 0 == field:
|
|
||||||
if 1 > len(f):
|
|
||||||
return None
|
|
||||||
return f[0].strip('<>')
|
|
||||||
else:
|
|
||||||
if field >= len(f):
|
|
||||||
return None
|
|
||||||
return f[field]
|
|
||||||
|
|
||||||
def register_event(t, callback, args):
|
def register_event(t, callback, args):
|
||||||
joblist.append((t, callback, args))
|
joblist.append((t, callback, args))
|
||||||
|
|
||||||
@@ -119,8 +105,9 @@ def parse_skynet(args):
|
|||||||
'msg': '''I'm an independent bot and have nothing to do with other artificial intelligence systems!'''
|
'msg': '''I'm an independent bot and have nothing to do with other artificial intelligence systems!'''
|
||||||
}
|
}
|
||||||
|
|
||||||
def data_parse_other(data):
|
def data_parse_other(msg):
|
||||||
reply_user = get_reply_data(data)
|
data = msg['body']
|
||||||
|
reply_user = msg['mucnick']
|
||||||
|
|
||||||
for p in plugins['parse']:
|
for p in plugins['parse']:
|
||||||
if ratelimit_exceeded(p['ratelimit_class']):
|
if ratelimit_exceeded(p['ratelimit_class']):
|
||||||
@@ -477,7 +464,8 @@ def command_else(args):
|
|||||||
'msg': args['reply_user'] + ''': I'm a bot (highlight me with 'info' for more information).'''
|
'msg': args['reply_user'] + ''': I'm a bot (highlight me with 'info' for more information).'''
|
||||||
}
|
}
|
||||||
|
|
||||||
def data_parse_commands(data):
|
def data_parse_commands(msg):
|
||||||
|
data = msg['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
|
||||||
@@ -492,9 +480,8 @@ def data_parse_commands(data):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
reply_user = get_reply_data(data)
|
reply_user = msg['mucnick']
|
||||||
argv0 = get_reply_data(data, field=2)
|
(argv0, argv1) = (words[0], words[1])
|
||||||
argv1 = get_reply_data(data, field=3)
|
|
||||||
|
|
||||||
for p in plugins['command']:
|
for p in plugins['command']:
|
||||||
if ratelimit_exceeded(p['ratelimit_class']):
|
if ratelimit_exceeded(p['ratelimit_class']):
|
||||||
|
|||||||
@@ -251,8 +251,8 @@ def handle_msg(msg):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if True != extract_url(content):
|
if True != extract_url(content):
|
||||||
plugins.data_parse_commands(content)
|
plugins.data_parse_commands(msg)
|
||||||
plugins.data_parse_other(content)
|
plugins.data_parse_other(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
class bot(ClientXMPP):
|
class bot(ClientXMPP):
|
||||||
|
|||||||
Reference in New Issue
Block a user