From b73babb4bfcacedc067a512e85913c77c574d859 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 --- config.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index 7f3f9c4..5ea991b 100644 --- a/config.py +++ b/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 83afbcf53ad2af9b7ee82c69f501068fb9b7b8f4 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 --- config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config.py b/config.py index 5ea991b..eba1f09 100644 --- a/config.py +++ b/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 d720bcab3a35330962211980dfeedf5f2016522e Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:48:34 +0200 Subject: reaktor config: introduce simple_command --- config.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/config.py b/config.py index eba1f09..90f33d3 100644 --- a/config.py +++ b/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 From 1e80665ab64bbcd783188c1c87afa5e81c126694 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:49:11 +0200 Subject: reaktor commands caps: fix typo --- commands/caps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/caps b/commands/caps index d024557..b5d6642 100755 --- a/commands/caps +++ b/commands/caps @@ -10,4 +10,4 @@ def load_config(filename): config = load_config(os.environ['config_filename']) print('Private: '+' '.join(filter(None,[ x.get('capname',None) for x in config.commands]))) -print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands]))) +print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands]))) -- cgit v1.2.3