Added modules

This commit is contained in:
Matthias Schiffer 2010-05-02 20:28:17 +02:00
parent 41fec54c30
commit 0277a779c9
8 changed files with 77 additions and 21 deletions

0
modules/__init__.py Normal file
View file

12
modules/base.py Normal file
View file

@ -0,0 +1,12 @@
class ModuleBase:
def __init__(self, manager):
self.manager = manager
def commands(self):
return []
def message(self, message_type, message_from, message_subject, message_body, reply):
pass
def groupchat(self, room, message_from, message_body, reply):
pass

18
modules/help.py Normal file
View file

@ -0,0 +1,18 @@
from base import ModuleBase
import re
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
def commands(self):
return [('!help', 'Zeigt diese Hilfe an...')]
def groupchat(self, room, message_from, message_body, reply):
if not re.match(r'!help(?:\W|\Z)', message_body):
return
commands = reduce(lambda l, mod: l + mod.commands(), self.manager.modules, [])
helpstring = reduce(lambda s, (c, h): s + c + ': ' + h + '\n', commands, '')
reply('Befehle:\n\n' + helpstring)