diff options
Diffstat (limited to 'update_topic.py')
-rw-r--r-- | update_topic.py | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/update_topic.py b/update_topic.py index 47a6064..c63ca14 100644 --- a/update_topic.py +++ b/update_topic.py @@ -1,7 +1,7 @@ #!/usr/bin/env python """ update_topic.py - Keep topic in #spline up-to-date -Copyright 2015, Alexander Sulfrian <alex@spline.inf.fu-berlin.de> +Copyright 2015-2016, Alexander Sulfrian <alex@spline.inf.fu-berlin.de> Licensed under the Eiffel Forum License 2. http://inamidst.com/phenny/ @@ -16,13 +16,21 @@ from dateutil.relativedelta import relativedelta from calendar import TUESDAY -CHANNEL = '#spline' -FROMAT = 'http://padlite.spline.de/p/treffen%y%m%d' -REGEX = re.compile(r'.*(http://padlite\.spline\.de/p/treffen[0-9]{6}).*') +DEFAULT_CONFIG = { + 'channel': '#spline', + 'format': 'http://padlite.spline.de/p/treffen%y%m%d', + 'regex': r'.*(http://padlite\.spline\.de/p/treffen[0-9]{6}).*', +} def setup(phenny): - Scheduler(phenny) + config = dict() + config.update(DEFAULT_CONFIG) + config.update(getattr(phenny.config, 'update_topic', dict())) + config['regex'] = re.compile(config['regex']) + phenny.data['update_topic.config'] = config + + Scheduler(config, phenny) class Timer(object): @@ -44,7 +52,8 @@ class Timer(object): class Scheduler(asyncore.dispatcher): - def __init__(self, phenny): + def __init__(self, config, phenny): + self.config = config self.phenny = phenny self.phenny._orig_close = self.phenny.close self.phenny.close = (lambda: self._phenny_close()) @@ -73,7 +82,7 @@ class Scheduler(asyncore.dispatcher): def _exec(self): # get topic, topic update is handled if a topic is received - self.phenny.write(['TOPIC'], CHANNEL) + self.phenny.write(['TOPIC'], self.config['channel']) def seconds_until(when): @@ -87,16 +96,20 @@ def get_next_meeting(): def update_topic(phenny, channel, topic): - if channel != CHANNEL: + if phenny.data.get('update_topic.config') is None: + return + + config = phenny.data['update_topic.config'] + if channel != config['channel']: return - match = REGEX.match(topic) + match = config['regex'].match(topic) if match is None: return new_topic = topic.replace( match.groups()[0], - get_next_meeting().strftime(FROMAT), + get_next_meeting().strftime(config['format']), 1) if new_topic != topic: |