summaryrefslogtreecommitdiffstats
path: root/update_topic.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-05-10 04:40:06 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2016-05-10 04:43:23 +0200
commitfd6eaca69525a54bae443fc2615c35b601bcf1cd (patch)
tree4a38cd413daa2e2c137f767b9827157e74b3e234 /update_topic.py
parent2545186173e8ca7f937764a4cc777557a691e16e (diff)
downloadupdate-topic-fd6eaca69525a54bae443fc2615c35b601bcf1cd.tar.gz
update-topic-fd6eaca69525a54bae443fc2615c35b601bcf1cd.tar.bz2
update-topic-fd6eaca69525a54bae443fc2615c35b601bcf1cd.zip
Add config option
You can now have something like this in your phenny config: 'update_topic': { 'channel': '#channel', 'format': 'http://url.example.com/%y%m%d', 'regex': r'.*(http://url.example.com/[0-9]{6}).*', }
Diffstat (limited to 'update_topic.py')
-rw-r--r--update_topic.py33
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: