summaryrefslogtreecommitdiffstats
path: root/Reaktor
diff options
context:
space:
mode:
authormakefu <root@pigstarter.de>2014-04-25 13:38:18 +0200
committermakefu <root@pigstarter.de>2014-04-25 13:38:18 +0200
commit8070f4a259cc02983ca7d3c8e86cb8da816a5c3b (patch)
tree9785c0db5c0b0f88c2f2eecf476eb1c7b22c56a6 /Reaktor
parentc35d7c4e017baa57c14f1fb4b48f18e153ced549 (diff)
parent7bf0b790b95d97d33e57a4e52cf7681bc6366d98 (diff)
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'Reaktor')
-rw-r--r--Reaktor/IRC/getconf.py7
-rw-r--r--Reaktor/IRC/ircasy.py5
-rwxr-xr-xReaktor/IRC/reaktor.py3
-rw-r--r--Reaktor/config.py33
4 files changed, 29 insertions, 19 deletions
diff --git a/Reaktor/IRC/getconf.py b/Reaktor/IRC/getconf.py
index f9cd4404..168c908c 100644
--- a/Reaktor/IRC/getconf.py
+++ b/Reaktor/IRC/getconf.py
@@ -9,14 +9,17 @@ import os
def make_getconf(filename):
- def getconf(prop):
+ def getconf(prop, default_value=None):
prop_split = prop.split('.')
string = ''
config = load_config(filename)
#imp.reload(config)
tmp = config.__dict__
for pr in prop_split:
- tmp = tmp[pr]
+ if pr in tmp:
+ tmp = tmp[pr]
+ else:
+ return default_value
return tmp
return getconf
diff --git a/Reaktor/IRC/ircasy.py b/Reaktor/IRC/ircasy.py
index 259ea98c..9a7f44f3 100644
--- a/Reaktor/IRC/ircasy.py
+++ b/Reaktor/IRC/ircasy.py
@@ -114,10 +114,7 @@ class asybot(asychat):
self.on_kick(prefix, command, params, rest)
elif command == 'JOIN':
- try:
- self.on_join(prefix, command, params, rest)
- except:
- pass
+ self.on_join(prefix, command, params, rest)
elif command == '433':
# ERR_NICKNAMEINUSE, retry with another name
diff --git a/Reaktor/IRC/reaktor.py b/Reaktor/IRC/reaktor.py
index b53ef651..bfd08d9f 100755
--- a/Reaktor/IRC/reaktor.py
+++ b/Reaktor/IRC/reaktor.py
@@ -36,7 +36,7 @@ class Reaktor(asybot):
return False
def on_join(self, prefix, command, params, rest):
- for command in getconf('on_join'):
+ for command in getconf('on_join', []):
self.execute_command(command, None, prefix, params)
def on_privmsg(self, prefix, command, params, rest):
@@ -81,7 +81,6 @@ class Reaktor(asybot):
target.append(env['_from'])
log.debug('target:' +str(target))
- env['config_filename'] = os.path.abspath(self.config)
start = time()
try:
p = popen(myargv, bufsize=1, stdout=PIPE, stderr=PIPE, env=env, cwd=cwd)
diff --git a/Reaktor/config.py b/Reaktor/config.py
index 0a01c5cb..7f3f9c40 100644
--- a/Reaktor/config.py
+++ b/Reaktor/config.py
@@ -1,11 +1,11 @@
-from os import environ
+from os.path import abspath, expanduser
+import re
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
@@ -19,14 +19,25 @@ irc_channels = [
]
admin_file='admin.lst'
auth_file='auth.lst'
-def default_command(cmd):
+
+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, env={}):
return {
'capname': cmd,
- 'pattern': '^(?:' + name + '|\\*):\\s*' + cmd + '\\s*(?:\\s+(?P<args>.*))?$',
- 'argv': [ 'commands/' + cmd ] }
+ 'pattern': '^' + me_or_us + ':\\s*' + cmd + '\\s*(?:\\s+(?P<args>.*))?$',
+ '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'),
@@ -34,19 +45,19 @@ public_commands = [
default_command('nocommand'),
{
'capname': 'tell',
- 'pattern': '^' + name + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'pattern': '^' + me_or_us + ':\\s*' + 'tell' + '\\s*(?:\\s+(?P<args>.*))?$',
'argv': [ 'commands/tell-on_privmsg' ],
'env': { 'state_file': workdir + '/tell.txt' }
},
# command not found
- { 'pattern': '^(?:' + name + '|\\*):.*',
+ { 'pattern': '^' + me_or_us + ':.*',
'argv': [ 'commands/respond','You are made of stupid!'] },
# "highlight"
- { 'pattern': '.*\\b' + name + '\\b.*',
+ { 'pattern': '.*' + me + '.*',
'argv': [ 'commands/say', 'I\'m famous' ] },
# identify via direct connect
{ 'capname': 'identify',
- 'pattern': '^identify' + '\\s*(?:\\s+(?P<args>.*))?$',
+ 'pattern': '^identify' + '\\s*(?:\\s+(?P<args>.*))?$',
'argv' : [ 'commands/identify' ]}
]
commands = [