From f95b596818a9ade81f9010b25923d0804a0c4469 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 11 May 2010 21:38:45 +0200 Subject: Improved module handler; improved mensa formatting --- curunir.py | 55 +++-------------------------------------------------- modules/__init__.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ modules/mensa.py | 6 ++++-- 3 files changed, 56 insertions(+), 54 deletions(-) diff --git a/curunir.py b/curunir.py index 824a7c6..6b6ed8a 100644 --- a/curunir.py +++ b/curunir.py @@ -1,58 +1,9 @@ -from connection.xmpp import XMPPConnection - import signal, sys, traceback -from config import config -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)) +from config import config +from modules import ModuleManager +from connection.xmpp import XMPPConnection - run = True diff --git a/modules/__init__.py b/modules/__init__.py index 49a460a..403bbc9 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -19,3 +19,52 @@ class ModuleBase: def topic(self, room, nick, text, handler): pass + +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)) diff --git a/modules/mensa.py b/modules/mensa.py index 96f2275..9ff4bcb 100644 --- a/modules/mensa.py +++ b/modules/mensa.py @@ -100,8 +100,10 @@ class Module(ModuleBase): s = s.replace('<', '<') s = s.replace('>', '>') s = s.replace('"', '"') - s = s.replace('
', ' ‒ ') - s = re.sub('\s+', ' ', s) + s = s.replace('
', ' ') + s = re.sub(r'-\s+', '-', s) + s = re.sub(r'\s+', ' ', s) + s = re.sub(r'([a-zäöüß])-([a-zäöüß])', r'\1\2', s) s = re.sub(r']*>(.+?)', r'\1', s) return s -- cgit v1.2.3