Improved topic module
This commit is contained in:
parent
bb0168b6b8
commit
dbc091688f
2 changed files with 45 additions and 16 deletions
|
@ -33,6 +33,7 @@ class MucHandler(MucRoomHandler):
|
||||||
|
|
||||||
def set_topic(self, topic):
|
def set_topic(self, topic):
|
||||||
self.room_state.set_subject(topic)
|
self.room_state.set_subject(topic)
|
||||||
|
self.room_state.subject = topic
|
||||||
|
|
||||||
def message_received(self, user, stanza):
|
def message_received(self, user, stanza):
|
||||||
if(user == None or user.same_as(self.room_state.me) or stanza.get_body() == None):
|
if(user == None or user.same_as(self.room_state.me) or stanza.get_body() == None):
|
||||||
|
|
|
@ -8,22 +8,50 @@ class Module(ModuleBase):
|
||||||
ModuleBase.__init__(self, manager)
|
ModuleBase.__init__(self, manager)
|
||||||
|
|
||||||
def commands(self):
|
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):
|
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
|
return
|
||||||
|
|
||||||
if not re.match(r'!topic\W', text):
|
if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text):
|
||||||
handler.reply(handler.get_topic())
|
topic = handler.get_topic()
|
||||||
|
if topic is None or topic == '':
|
||||||
|
handler.reply('Es ist kein Topic gesetzt.')
|
||||||
return
|
return
|
||||||
|
topics = [s.strip() for s in topic.split('|')]
|
||||||
topic = re.sub(r'!topic\W+', '', text)
|
idtopics = zip(range(len(topics)), topics)
|
||||||
if topic == '':
|
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()
|
||||||
if oldtopic != '' and oldtopic != None:
|
|
||||||
|
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
|
topic += ' | ' + oldtopic
|
||||||
|
|
||||||
handler.set_topic(topic)
|
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))
|
||||||
|
|
Reference in a new issue