summaryrefslogtreecommitdiffstats
path: root/modules/topic.py
blob: d878a911d22c358c4f17d3bbccbbf2dd5c9d8653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# -*- coding: utf-8 -*-

from . import ModuleBase
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')]
    
    def groupchat(self, room, nick, text, handler):
        if not re.match(r'!topic(?:\W|\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 == '':
            return
        
        oldtopic = handler.get_topic()
        if oldtopic != '' and oldtopic != None:
            topic += ' | ' + oldtopic
        
        handler.set_topic(topic)