Print new topic on change

This commit is contained in:
Matthias Schiffer 2012-04-22 17:50:52 +02:00
parent dbc091688f
commit 64efcb0fd8

View file

@ -14,19 +14,22 @@ class Module(ModuleBase):
('!topic d[el[ete]] <ID>', 'Entfernt das Topic mit der ID') ('!topic d[el[ete]] <ID>', '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): def groupchat(self, room, nick, text, handler):
if not re.match(r'!topic(?:\s|\Z)', text): if not re.match(r'!topic(?:\s|\Z)', text):
return return
if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text): if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text):
topic = handler.get_topic() self._reply_topic(handler, 'Aktuelles 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))
return return
oldtopic = handler.get_topic() oldtopic = handler.get_topic()
@ -40,6 +43,7 @@ class Module(ModuleBase):
topic += ' | ' + oldtopic topic += ' | ' + oldtopic
handler.set_topic(topic) handler.set_topic(topic)
self._reply_topic(handler, 'Neues Topic:')
return return
if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text): if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text):
@ -55,3 +59,4 @@ class Module(ModuleBase):
del topics[topicid] del topics[topicid]
handler.set_topic(' | '.join(topics)) handler.set_topic(' | '.join(topics))
self._reply_topic(handler, 'Neues Topic:')