2010-05-02 23:40:21 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2010-05-09 21:49:15 +02:00
|
|
|
from . import ModuleBase
|
2010-05-02 23:40:21 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
class Module(ModuleBase):
|
|
|
|
def __init__(self, manager):
|
|
|
|
ModuleBase.__init__(self, manager)
|
2012-04-22 17:43:15 +02:00
|
|
|
|
2010-05-02 23:40:21 +02:00
|
|
|
def commands(self):
|
2012-04-22 17:43:15 +02:00
|
|
|
return [
|
|
|
|
('!topic [s[how]]', 'Zeigt das aktuelle Topic mit IDs an'),
|
|
|
|
('!topic a[dd] <Topic>', 'Fügt einen Text zum Thema des Chatraums hinzu'),
|
|
|
|
('!topic d[el[ete]] <ID>', 'Entfernt das Topic mit der ID')
|
|
|
|
]
|
|
|
|
|
2012-04-22 17:50:52 +02:00
|
|
|
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))
|
|
|
|
|
2010-05-02 23:40:21 +02:00
|
|
|
def groupchat(self, room, nick, text, handler):
|
2012-04-22 17:43:15 +02:00
|
|
|
if not re.match(r'!topic(?:\s|\Z)', text):
|
2010-05-06 22:10:50 +02:00
|
|
|
return
|
2012-04-22 17:43:15 +02:00
|
|
|
|
|
|
|
if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text):
|
2012-04-22 17:50:52 +02:00
|
|
|
self._reply_topic(handler, 'Aktuelles Topic:')
|
2010-05-02 23:40:21 +02:00
|
|
|
return
|
2012-04-22 17:43:15 +02:00
|
|
|
|
2010-05-02 23:40:21 +02:00
|
|
|
oldtopic = handler.get_topic()
|
2012-04-22 17:43:15 +02:00
|
|
|
|
|
|
|
if re.match(r'!topic\s+a(?:dd)?\s', text):
|
|
|
|
topic = re.sub(r'!topic\s+a(?:dd)?\s+', '', text)
|
|
|
|
if topic == '':
|
|
|
|
return
|
|
|
|
|
|
|
|
if oldtopic != '' and oldtopic is not None:
|
|
|
|
topic += ' | ' + oldtopic
|
|
|
|
|
|
|
|
handler.set_topic(topic)
|
2012-04-22 17:50:52 +02:00
|
|
|
self._reply_topic(handler, 'Neues Topic:')
|
2012-04-22 17:43:15 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text):
|
|
|
|
try:
|
|
|
|
topicid = int(re.sub(r'!topic\s+d(?:el(?:ete)?)?\s+', '', text))
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
topics = [s.strip() for s in oldtopic.split('|')]
|
|
|
|
if topicid < 0 or topicid >= len(topics):
|
|
|
|
return
|
|
|
|
|
|
|
|
del topics[topicid]
|
|
|
|
|
|
|
|
handler.set_topic(' | '.join(topics))
|
2012-04-22 17:50:52 +02:00
|
|
|
self._reply_topic(handler, 'Neues Topic:')
|