From 31bf2d4d296347eece924dcfa690390f9a72deaf Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 12:58:24 +0200 Subject: reaktor config: use expanduser instead of environ --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 0a01c5c..4ca6d37 100644 --- a/config.py +++ b/config.py @@ -1,11 +1,11 @@ -from os import environ +from os.path import expanduser debug = True # CAVEAT name should not contains regex magic name = 'crabmanner' -workdir = environ['HOME'] + '/state' +workdir = expanduser('~') + '/state' irc_alarm_timeout = 300 irc_hammer_interval = 10 -- cgit v1.2.3 From 89cc9517383f7e01e7d2f3bd4781048d3c1139fb Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:08:46 +0200 Subject: reaktor: name must not be able to kill patterns --- config.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 4ca6d37..48406bf 100644 --- a/config.py +++ b/config.py @@ -1,8 +1,8 @@ from os.path import expanduser +import re debug = True -# CAVEAT name should not contains regex magic name = 'crabmanner' workdir = expanduser('~') + '/state' @@ -19,10 +19,14 @@ irc_channels = [ ] admin_file='admin.lst' auth_file='auth.lst' + +# name_re is used, so name cannot kill our patterns below +name_re = re.escape(name) + def default_command(cmd): return { 'capname': cmd, - 'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', + 'pattern': '^(?:' + name_re + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', 'argv': [ 'commands/' + cmd ] } public_commands = [ @@ -34,15 +38,15 @@ public_commands = [ default_command('nocommand'), { 'capname': 'tell', - 'pattern': '^' + name + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P.*))?$', + 'pattern': '^' + name_re + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P.*))?$', 'argv': [ 'commands/tell-on_privmsg' ], 'env': { 'state_file': workdir + '/tell.txt' } }, # command not found - { 'pattern': '^(?:' + name + '|\\*):.*', + { 'pattern': '^(?:' + name_re + '|\\*):.*', 'argv': [ 'commands/respond','You are made of stupid!'] }, # "highlight" - { 'pattern': '.*\\b' + name + '\\b.*', + { 'pattern': '.*\\b' + name_re + '\\b.*', 'argv': [ 'commands/say', 'I\'m famous' ] }, # identify via direct connect { 'capname': 'identify', -- cgit v1.2.3 From bf00ab1a5449bb0bf554b49fbd5da6e882a44b2e Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:19:50 +0200 Subject: reaktor config: unify ^(|*): --- config.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 48406bf..9054034 100644 --- a/config.py +++ b/config.py @@ -20,13 +20,14 @@ irc_channels = [ admin_file='admin.lst' auth_file='auth.lst' -# name_re is used, so name cannot kill our patterns below -name_re = re.escape(name) +# me is used, so name cannot kill our patterns below +me = '\\b' + re.escape(name) + '\\b' +me_or_us = '(?:' + me + '|\\*)' def default_command(cmd): return { 'capname': cmd, - 'pattern': '^(?:' + name_re + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', + 'pattern': '^' + me_or_us + ':\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', 'argv': [ 'commands/' + cmd ] } public_commands = [ @@ -38,19 +39,19 @@ public_commands = [ default_command('nocommand'), { 'capname': 'tell', - 'pattern': '^' + name_re + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P.*))?$', + 'pattern': '^' + me_or_us + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P.*))?$', 'argv': [ 'commands/tell-on_privmsg' ], 'env': { 'state_file': workdir + '/tell.txt' } }, # command not found - { 'pattern': '^(?:' + name_re + '|\\*):.*', + { 'pattern': '^' + me_or_us + ':.*', 'argv': [ 'commands/respond','You are made of stupid!'] }, # "highlight" - { 'pattern': '.*\\b' + name_re + '\\b.*', + { 'pattern': '.*' + me + '.*', 'argv': [ 'commands/say', 'I\'m famous' ] }, # identify via direct connect { 'capname': 'identify', - 'pattern': '^identify' + '\\s*(?:\\s+(?P.*))?$', + 'pattern': '^identify' + '\\s*(?:\\s+(?P.*))?$', 'argv' : [ 'commands/identify' ]} ] commands = [ -- cgit v1.2.3 From 97e2b11759fe3066b3d12bb9d47c981959c3cde8 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 25 Apr 2014 13:34:04 +0200 Subject: reaktor: move config_filename to config --- config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 9054034..7f3f9c4 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,4 @@ -from os.path import expanduser +from os.path import abspath, expanduser import re debug = True @@ -20,18 +20,24 @@ irc_channels = [ admin_file='admin.lst' auth_file='auth.lst' +config_filename = abspath(__file__) + # me is used, so name cannot kill our patterns below me = '\\b' + re.escape(name) + '\\b' me_or_us = '(?:' + me + '|\\*)' -def default_command(cmd): +def default_command(cmd, env={}): return { 'capname': cmd, 'pattern': '^' + me_or_us + ':\\s*' + cmd + '\\s*(?:\\s+(?P.*))?$', - 'argv': [ 'commands/' + cmd ] } + 'argv': [ 'commands/' + cmd ], + 'env': env + } public_commands = [ - default_command('caps'), + default_command('caps', env={ + 'config_filename': config_filename + }), default_command('hello'), default_command('badcommand'), default_command('rev'), -- cgit v1.2.3