summaryrefslogtreecommitdiffstats
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
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}).*', }
-rw-r--r--debian/changelog6
-rw-r--r--debian/copyright4
-rw-r--r--update_topic.py33
3 files changed, 31 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index d2628a3..c076f72 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+phenny-module-update-topic (0.5) UNRELEASED; urgency=low
+
+ * Add config option
+
+ -- Alexander Sulfrian <alex@spline.inf.fu-berlin.de> Tue, 10 May 2016 04:42:39 +0200
+
phenny-module-update-topic (0.4) UNRELEASED; urgency=low
* Fix python syntax for super calls
diff --git a/debian/copyright b/debian/copyright
index 0592154..ba4e129 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -12,7 +12,7 @@ Upstream Author(s):
Copyright:
- Copyright (C) 2015 Alexander Sulfrian
+ Copyright (C) 2015-2016 Alexander Sulfrian
License:
@@ -20,7 +20,7 @@ License:
The Debian packaging is:
- Copyright (C) 2015 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
+ Copyright (C) 2015-2016 Alexander Sulfrian <alex@spline.inf.fu-berlin.de>
and is licensed under the GPL version 3,
see "/usr/share/common-licenses/GPL-3".
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: