summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-04-22 17:43:15 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-04-22 17:43:15 +0200
commitdbc091688f1edbbffb8c70e29778a9437b2d0e47 (patch)
treeceb3429b9b20f2888d095f2f67975187c7d0e56a /modules
parentbb0168b6b8c1cad235c4fcd49a8b4232d4d07ee6 (diff)
downloadcurunir-dbc091688f1edbbffb8c70e29778a9437b2d0e47.tar
curunir-dbc091688f1edbbffb8c70e29778a9437b2d0e47.zip
Improved topic module
Diffstat (limited to 'modules')
-rw-r--r--modules/topic.py60
1 files changed, 44 insertions, 16 deletions
diff --git a/modules/topic.py b/modules/topic.py
index d878a91..7f4ca10 100644
--- a/modules/topic.py
+++ b/modules/topic.py
@@ -6,24 +6,52 @@ import re
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
-
+
def commands(self):
- return [('!topic [<Topic>]', 'Fügt einen Text zum Thema des Chatraums hinzu oder zeigt das aktuelle Topic an')]
-
+ 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')
+ ]
+
def groupchat(self, room, nick, text, handler):
- if not re.match(r'!topic(?:\W|\Z)', text):
+ if not re.match(r'!topic(?:\s|\Z)', text):
return
-
- if not re.match(r'!topic\W', text):
- handler.reply(handler.get_topic())
- return
-
- topic = re.sub(r'!topic\W+', '', text)
- if topic == '':
+
+ 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))
return
-
+
oldtopic = handler.get_topic()
- if oldtopic != '' and oldtopic != None:
- topic += ' | ' + oldtopic
-
- handler.set_topic(topic)
+
+ 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)
+ 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))