summaryrefslogtreecommitdiffstats
path: root/Reaktor/reaktor/config.py
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2015-09-04 22:08:40 +0200
committermakefu <github@syntax-fehler.de>2015-09-04 22:08:40 +0200
commit7b36e711d2b58ddd360ebe25ecbc2265c5ce76bb (patch)
treec0b44a9e69811873d530ebe2e355ba3e9653bbcb /Reaktor/reaktor/config.py
parente9e7d6baf986488c43d418887f6cf95f5d896189 (diff)
config: more logic in config file :(
Diffstat (limited to 'Reaktor/reaktor/config.py')
-rw-r--r--Reaktor/reaktor/config.py74
1 files changed, 37 insertions, 37 deletions
diff --git a/Reaktor/reaktor/config.py b/Reaktor/reaktor/config.py
index 56ef71e8..7f4837ca 100644
--- a/Reaktor/reaktor/config.py
+++ b/Reaktor/reaktor/config.py
@@ -2,45 +2,45 @@ import os
from os.path import abspath, expanduser,dirname,join
import reaktor # to get the path to the reaktor basedir
import re
+env = os.environ
-debug = True
+# TODO: put this somewhere else
+def str2bool(v):
+ return v.lower() in ("yes", "true", "t", "1")
+#### ENVIRON CONFIG
+# this provides a simple means of reconfiguring this config without the need to
+# copy-paste the whole thing
+debug = str2bool(env.get('REAKTOR_DEBUG',"False"))
# IRC_NICKNAME is set if the nick changes and the config is getting reloaded
+name = env.get('REAKTOR_NICKNAME','crabmanner')
+irc_server = env.get('REAKTOR_HOST','irc.freenode.org')
+irc_port = int(env.get('REAKTOR_PORT',6667))
# TODO: do not implement functionality in the config :\
-name = os.environ.get('IRC_NICKNAME','crabmanner')
+workdir = env.get('REAKTOR_STATEDIR',expanduser('~') + '/state')
+irc_channels = env.get('REAKTOR_CHANNELS','#krebs').split(',')
+#### static config
+# if you want to change this part you have to copy the config
+irc_alarm_timeout = 300
+irc_hammer_interval = 10
+irc_kill_timeout = 360
+irc_nickname = name
+irc_restart_timeout = 5
-#workdir = './state'
-workdir = expanduser('~') + '/state'
+#### IMPLEMENTATION
+# this config contains the implementation of how commands should match
# TODO: YAY more functionality in config.py ..
+# create the workdir somewhere # else in the code ...
# if this fails the bot will fail (which is ok)
if not os.path.isdir(workdir): os.makedirs(workdir)
-
-
-irc_alarm_timeout = 300
-irc_hammer_interval = 10
-irc_kill_timeout = 360
-irc_nickname = name
-irc_server = 'irc.freenode.org'
-irc_port = 6667
-irc_restart_timeout = 5
-irc_channels = [
- '#krebs'
-]
admin_file=workdir+'/admin.lst'
auth_file=workdir+'/auth.lst'
-nag_env={
- 'hosts_repo': 'https://github.com/krebscode/hosts',
- 'services_repo': 'gitolite@localhost:services',
- 'inspect_services': 'false'
-}
-
config_filename = abspath(__file__)
-
mod_dir=dirname(abspath(reaktor.__file__))
# the commands dirname (
dist_dir = abspath(join(mod_dir))
@@ -49,16 +49,18 @@ dist_dir = abspath(join(mod_dir))
# TODO: name may change after reconnect, then this pattern fails to match
# this may need a complete refactor of how to create patterns and matches
+
+## IMPLEMENTATION
+
me = '\\b' + re.escape(name) + '\\b'
me_or_us = '(?:' + me + '|\\*)'
+indirect_pattern='^'+me_or_us+':\\s*{}\\s*(?:\\s+(?P<args>.*))?$'
def distc(cmd):
- """ builds a path to a cmd in the distribution command folder"""
+ """ builds a path to a cmd in the command folder of the Reaktor distribution"""
return join(dist_dir,"commands",cmd)
-# using partial formatting {{}}
-indirect_pattern='^{}:\\s*{{}}\\s*(?:\\s+(?P<args>.*))?$'.format(me_or_us)
def default_command(cap, cmd=None, env=None):
""" (botname|*): cmd args
@@ -90,32 +92,33 @@ def simple_command(cap, cmd=None, env=None):
'env': env
}
+# unauthenticated commands
public_commands = [
default_command('caps', env={
'config_filename': config_filename
}),
default_command('hello'),
default_command('badcommand'),
- default_command('rev'),
+ #default_command('rev'), # TODO: when uploaded to pypi the rev gets lost
+ default_command('version'),
default_command('uptime'),
default_command('nocommand'),
default_command('tell', cmd='tell-on_privmsg', env={
'state_file': workdir + '/tell.txt'
}),
- # TODO this is disabled until someone fixes it
- #default_command('nag', env=nag_env),
simple_command('identify', env={
'config_filename': config_filename
}),
# command not found
- { 'pattern': '^' + me_or_us + ':.*',
- 'argv': [ distc('respond'),'You are made of stupid!'] },
+ #{ 'pattern': '^' + me_or_us + ':.*',
+ # 'argv': [ distc('respond'),'You are made of stupid!'] },
# "highlight"
{ 'pattern': '.*' + me + '.*',
'argv': [ distc('say'), 'I\'m famous' ] },
# identify via direct connect
]
+# authenticated commands
commands = [
default_command('reload'),
]
@@ -128,11 +131,8 @@ on_join = [
}
]
+# Timer
on_ping = [
- {
- 'capname': 'nag',
- 'argv': [ distc('nag') ],
- 'env': nag_env,
- 'targets': irc_channels
- }
]
+
+## END IMPLEMENTATION