From 64efcb0fd8afe3bd208e509b9eca0f227be6edb2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 22 Apr 2012 17:50:52 +0200 Subject: Print new topic on change --- modules/topic.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'modules') diff --git a/modules/topic.py b/modules/topic.py index 7f4ca10..bdc5143 100644 --- a/modules/topic.py +++ b/modules/topic.py @@ -14,19 +14,22 @@ class Module(ModuleBase): ('!topic d[el[ete]] ', 'Entfernt das Topic mit der ID') ] + def _reply_topic(self, handler, prefix): + topic = handler.get_topic() + if topic is None or topic == '': + handler.reply('Es ist kein Topic gesetzt.') + return + topics = [s.strip() for s in topic.split('|')] + idtopics = zip(range(len(topics)), topics) + idtopicstrings = ["%i: %s" % t for t in idtopics] + handler.reply(prefix + '\n\n' + '\n'.join(idtopicstrings)) + def groupchat(self, room, nick, text, handler): if not re.match(r'!topic(?:\s|\Z)', text): return if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text): - topic = handler.get_topic() - if topic is None or topic == '': - handler.reply('Es ist kein Topic gesetzt.') - return - topics = [s.strip() for s in topic.split('|')] - idtopics = zip(range(len(topics)), topics) - idtopicstrings = ["%i: %s" % t for t in idtopics] - handler.reply('Aktuelles Topic:\n\n' + '\n'.join(idtopicstrings)) + self._reply_topic(handler, 'Aktuelles Topic:') return oldtopic = handler.get_topic() @@ -40,6 +43,7 @@ class Module(ModuleBase): topic += ' | ' + oldtopic handler.set_topic(topic) + self._reply_topic(handler, 'Neues Topic:') return if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text): @@ -55,3 +59,4 @@ class Module(ModuleBase): del topics[topicid] handler.set_topic(' | '.join(topics)) + self._reply_topic(handler, 'Neues Topic:') -- cgit v1.2.3