summaryrefslogtreecommitdiffstats
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
parente9e7d6baf986488c43d418887f6cf95f5d896189 (diff)
config: more logic in config file :(
-rw-r--r--Reaktor/reaktor/__init__.py1
-rwxr-xr-xReaktor/reaktor/commands/version27
-rw-r--r--Reaktor/reaktor/config.py74
-rw-r--r--Reaktor/setup.py3
4 files changed, 67 insertions, 38 deletions
diff --git a/Reaktor/reaktor/__init__.py b/Reaktor/reaktor/__init__.py
index e69de29b..4fe60b4d 100644
--- a/Reaktor/reaktor/__init__.py
+++ b/Reaktor/reaktor/__init__.py
@@ -0,0 +1 @@
+__version__="0.4.0"
diff --git a/Reaktor/reaktor/commands/version b/Reaktor/reaktor/commands/version
new file mode 100755
index 00000000..ff3c48fe
--- /dev/null
+++ b/Reaktor/reaktor/commands/version
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+url="https://pypi.python.org/pypi/Reaktor/json"
+import requests
+import reaktor
+cur_version = reaktor.__version__
+
+ret = requests.get(url).json()
+latest_version = ret["info"]["version"]
+
+def vt(v):
+ return tuple(map(int, (v.split("."))))
+
+try:
+ rel = ret["releases"][cur_version][0]["upload_time"]
+except:
+ rel = "unknown release date"
+print("{} - {}".format(cur_version,rel))
+if vt(latest_version) > vt(cur_version):
+ print(" newer release available: {}".format(latest_version))
+elif vt(latest_version) < vt(cur_version):
+ print(" ahead of official release: {}".format(latest_version))
+else:
+ # on the most current release
+ pass
+
+
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
diff --git a/Reaktor/setup.py b/Reaktor/setup.py
index 7b781713..e96568fa 100644
--- a/Reaktor/setup.py
+++ b/Reaktor/setup.py
@@ -1,9 +1,10 @@
import sys
from setuptools import setup
+import reaktor
setup(
name='Reaktor',
- version='0.3.2',
+ version=reaktor.__version__,
description='an IRC bot based on asyn* libs',
long_description=open("README.md").read(),