2010-05-09 21:49:15 +02:00
|
|
|
class ModuleBase:
|
|
|
|
def __init__(self, manager):
|
|
|
|
self.manager = manager
|
|
|
|
|
|
|
|
def commands(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def helptexts(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def groupchat(self, room, nick, text, handler):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def join(self, room, nick, show, status, handler):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def leave(self, room, nick, show, status, handler):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def topic(self, room, nick, text, handler):
|
|
|
|
pass
|
2010-05-11 21:38:45 +02:00
|
|
|
|
|
|
|
class ModuleManager:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
|
|
|
self._modules = {}
|
|
|
|
|
|
|
|
for mod in config['modules']:
|
|
|
|
self.get(mod)
|
|
|
|
|
|
|
|
def get(self, name):
|
|
|
|
if not name in self._modules:
|
|
|
|
mod = __import__('modules.' + name, globals(), locals(), ['Module'])
|
|
|
|
self._modules[name] = mod.Module(self)
|
|
|
|
|
|
|
|
return self._modules[name]
|
|
|
|
|
|
|
|
def commands(self):
|
|
|
|
return reduce(lambda l, mod: l + mod.commands(), self._modules.itervalues(), [])
|
|
|
|
|
|
|
|
def helptexts(self):
|
|
|
|
return reduce(lambda l, mod: l + mod.helptexts(), self._modules.itervalues(), [])
|
|
|
|
|
|
|
|
def groupchat(self, room, nick, text, handler):
|
|
|
|
for mod in self._modules.itervalues():
|
|
|
|
try:
|
|
|
|
mod.groupchat(room, nick, text, handler)
|
|
|
|
except:
|
|
|
|
handler.reply(traceback.format_exc(5))
|
|
|
|
|
|
|
|
def join(self, room, nick, show, status, handler):
|
|
|
|
for mod in self._modules.itervalues():
|
|
|
|
try:
|
|
|
|
mod.join(room, nick, show, status, handler)
|
|
|
|
except:
|
|
|
|
handler.reply(traceback.format_exc(5))
|
|
|
|
|
|
|
|
def leave(self, room, nick, show, status, handler):
|
|
|
|
for mod in self._modules.itervalues():
|
|
|
|
try:
|
|
|
|
mod.leave(room, nick, show, status, handler)
|
|
|
|
except:
|
|
|
|
handler.reply(traceback.format_exc(5))
|
|
|
|
|
|
|
|
def topic(self, room, nick, text, handler):
|
|
|
|
for mod in self._modules.itervalues():
|
|
|
|
try:
|
|
|
|
mod.topic(room, nick, text, handler)
|
|
|
|
except:
|
|
|
|
handler.reply(traceback.format_exc(5))
|