From 14751fbcb177f70cf8989f4d27c566b2576ebb70 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:42:45 +0200 Subject: reaktor config: tell is a default_command --- Reaktor/config.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'Reaktor/config.py') diff --git a/Reaktor/config.py b/Reaktor/config.py index 7f3f9c40..5ea991b0 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -26,10 +26,11 @@ config_filename = abspath(__file__) me = '\\b' + re.escape(name) + '\\b' me_or_us = '(?:' + me + '|\\*)' -def default_command(cmd, env={}): +def default_command(cap, cmd=None, env={}): + if cmd == None: cmd=cap return { - 'capname': cmd, - 'pattern': '^' + me_or_us + ':\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', + 'capname': cap, + 'pattern': '^' + me_or_us + ':\\s*' + cap + '\\s*(?:\\s+(?P.*))?$', 'argv': [ 'commands/' + cmd ], 'env': env } @@ -43,12 +44,9 @@ public_commands = [ default_command('rev'), default_command('uptime'), default_command('nocommand'), - { - 'capname': 'tell', - 'pattern': '^' + me_or_us + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P.*))?$', - 'argv': [ 'commands/tell-on_privmsg' ], - 'env': { 'state_file': workdir + '/tell.txt' } - }, + default_command('tell', cmd='tell-on_privmsg', env={ + 'state_file': workdir + '/tell.txt' + }), # command not found { 'pattern': '^' + me_or_us + ':.*', 'argv': [ 'commands/respond','You are made of stupid!'] }, -- cgit v1.2.3 From 9e5e76fd2532a47b0cc47f4d01266b7c35299470 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:43:08 +0200 Subject: reaktor config: identify needs config_filename --- Reaktor/config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Reaktor/config.py') diff --git a/Reaktor/config.py b/Reaktor/config.py index 5ea991b0..eba1f093 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -56,7 +56,11 @@ public_commands = [ # identify via direct connect { 'capname': 'identify', 'pattern': '^identify' + '\\s*(?:\\s+(?P.*))?$', - 'argv' : [ 'commands/identify' ]} + 'argv' : [ 'commands/identify' ], + 'env': { + 'config_filename': config_filename + } + } ] commands = [ default_command('reload') -- cgit v1.2.3 From ebf658d66ce61a21c3363a8313d847efaf13d21c Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:48:34 +0200 Subject: reaktor config: introduce simple_command --- Reaktor/config.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Reaktor/config.py') diff --git a/Reaktor/config.py b/Reaktor/config.py index eba1f093..90f33d38 100644 --- a/Reaktor/config.py +++ b/Reaktor/config.py @@ -35,6 +35,15 @@ def default_command(cap, cmd=None, env={}): 'env': env } +def simple_command(cap, cmd=None, env={}): + if cmd == None: cmd=cap + return { + 'capname': cap, + 'pattern': '^' + cap + '\\s*(?:\\s+(?P.*))?$', + 'argv' : [ 'commands/' + cmd ], + 'env': env + } + public_commands = [ default_command('caps', env={ 'config_filename': config_filename @@ -54,13 +63,9 @@ public_commands = [ { 'pattern': '.*' + me + '.*', 'argv': [ 'commands/say', 'I\'m famous' ] }, # identify via direct connect - { 'capname': 'identify', - 'pattern': '^identify' + '\\s*(?:\\s+(?P.*))?$', - 'argv' : [ 'commands/identify' ], - 'env': { - 'config_filename': config_filename - } - } + simple_command('identify', env={ + 'config_filename': config_filename + }) ] commands = [ default_command('reload') -- cgit v1.2.3