summaryrefslogtreecommitdiffstats
path: root/Reaktor
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-04-25 12:02:03 +0200
committermakefu <github@syntax-fehler.de>2014-04-25 12:02:03 +0200
commit9bdee602a30f715c9ba2583d3948c360448c670b (patch)
treea3262e6febda77bc87de49371ecd0fdb874bdc3a /Reaktor
parentc25a00dca1af27a95ccbc521075375d1df866914 (diff)
make config file a parameter
Diffstat (limited to 'Reaktor')
-rw-r--r--Reaktor/IRC/ircasy.py5
-rwxr-xr-xReaktor/IRC/reaktor.py47
-rwxr-xr-xReaktor/index2
3 files changed, 32 insertions, 22 deletions
diff --git a/Reaktor/IRC/ircasy.py b/Reaktor/IRC/ircasy.py
index 9a7f44f3..259ea98c 100644
--- a/Reaktor/IRC/ircasy.py
+++ b/Reaktor/IRC/ircasy.py
@@ -114,7 +114,10 @@ class asybot(asychat):
self.on_kick(prefix, command, params, rest)
elif command == 'JOIN':
- self.on_join(prefix, command, params, rest)
+ try:
+ self.on_join(prefix, command, params, rest)
+ except:
+ pass
elif command == '433':
# ERR_NICKNAMEINUSE, retry with another name
diff --git a/Reaktor/IRC/reaktor.py b/Reaktor/IRC/reaktor.py
index 5e5156ad..b53ef651 100755
--- a/Reaktor/IRC/reaktor.py
+++ b/Reaktor/IRC/reaktor.py
@@ -6,9 +6,9 @@ from translate_colors import translate_colors
import shlex
from re import split, search, match
-config_filename = './config.py'
+default_config = './config.py'
from getconf import make_getconf
-getconf = make_getconf(config_filename)
+getconf = None
import logging,logging.handlers
log = logging.getLogger('asybot')
@@ -16,24 +16,25 @@ log = logging.getLogger('asybot')
#formatter = logging.Formatter( '%(filename)s: %(levelname)s: %(message)s')
#hdlr.setFormatter(formatter)
#log.addHandler(hdlr)
-logging.basicConfig(level = logging.DEBUG if getconf('debug') else logging.INFO)
-restart_timeout = getconf('irc_restart_timeout') or 5
-def is_admin(prefix):
- try:
- with open(getconf('auth_file')) as f:
- for line in f:
- if line.strip() == prefix:
- return True
- except Exception as e:
- log.info(e)
- return False
class Reaktor(asybot):
- def __init__(self):
+ def __init__(self,config=default_config):
+ self.config = config
+ log.info("using config file %s"%(config))
asybot.__init__(self, getconf('irc_server'), getconf('irc_port'), getconf('irc_nickname'), getconf('irc_channels'), hammer_interval=getconf('irc_hammer_interval'), alarm_timeout=getconf('irc_alarm_timeout'), kill_timeout=getconf('irc_kill_timeout'))
+ def is_admin(self,prefix):
+ try:
+ with open(getconf('auth_file')) as f:
+ for line in f:
+ if line.strip() == prefix:
+ return True
+ except Exception as e:
+ log.info(e)
+ return False
+
def on_join(self, prefix, command, params, rest):
for command in getconf('on_join'):
self.execute_command(command, None, prefix, params)
@@ -42,7 +43,7 @@ class Reaktor(asybot):
for command in getconf('commands'):
y = match(command['pattern'], rest)
if y:
- if not is_admin(prefix):
+ if not self.is_admin(prefix):
self.PRIVMSG(params,'unauthorized!')
else:
return self.execute_command(command, y, prefix, params)
@@ -61,9 +62,11 @@ class Reaktor(asybot):
#TODO: allow only commands below ./commands/
exe = join(dirname(realpath(dirname(__file__))), command['argv'][0])
myargv = [exe] + command['argv'][1:]
-
- if match and match.groupdict().get('args', None):
- myargv += shlex.split(match.groupdict()['args'])
+ try:
+ if match and match.groupdict().get('args', None):
+ myargv += shlex.split(match.groupdict()['args'])
+ except:
+ log.info("cannot parse args!")
cwd = getconf('workdir')
@@ -78,7 +81,7 @@ class Reaktor(asybot):
target.append(env['_from'])
log.debug('target:' +str(target))
- env['config_filename'] = os.path.abspath(config_filename)
+ env['config_filename'] = os.path.abspath(self.config)
start = time()
try:
p = popen(myargv, bufsize=1, stdout=PIPE, stderr=PIPE, env=env, cwd=cwd)
@@ -103,5 +106,9 @@ class Reaktor(asybot):
self.ME(target, 'mimimi')
if __name__ == "__main__":
- Reaktor()
+ import sys
+ conf = sys.argv[1] if len(sys.argv) == 2 else default_config
+ getconf = make_getconf(conf)
+ logging.basicConfig(level = logging.DEBUG if getconf('debug') else logging.INFO)
+ Reaktor(conf)
loop()
diff --git a/Reaktor/index b/Reaktor/index
index ac647ca3..fc59cd73 100755
--- a/Reaktor/index
+++ b/Reaktor/index
@@ -4,4 +4,4 @@ set -euf
# cd //Reaktor
cd $(dirname $(readlink -f $0))
-exec IRC/index
+exec IRC/index "$@"