summaryrefslogtreecommitdiffstats
path: root/curunir.py
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-05-09 21:49:15 +0200
committerMatthias Schiffer <matthias@gamezock.de>2010-05-09 21:49:15 +0200
commit1384d1976fa984b6b254c93677363f67944c0c7a (patch)
tree698faff3ef045df7f2a8e3bd75e6b1e04a397b28 /curunir.py
parente5cd4bb20328110561ee9956f948b97c378cf671 (diff)
downloadcurunir-1384d1976fa984b6b254c93677363f67944c0c7a.tar
curunir-1384d1976fa984b6b254c93677363f67944c0c7a.zip
Made everything much more error resistant
Diffstat (limited to 'curunir.py')
-rw-r--r--curunir.py68
1 files changed, 54 insertions, 14 deletions
diff --git a/curunir.py b/curunir.py
index 3c0d933..5383fe3 100644
--- a/curunir.py
+++ b/curunir.py
@@ -1,22 +1,57 @@
from connection.xmpp import XMPPConnection
-import signal, sys
+import signal, sys, traceback
from config import config
class ModuleManager:
def __init__(self, config):
self.config = config
- self.modules = {}
+ self._modules = {}
for mod in config['modules']:
self.get(mod)
def get(self, name):
- if not name in self.modules:
+ if not name in self._modules:
mod = __import__('modules.' + name, globals(), locals(), ['Module'])
- self.modules[name] = mod.Module(self)
+ self._modules[name] = mod.Module(self)
- return self.modules[name]
+ 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.leave(room, nick, text, handler)
+ except:
+ handler.reply(traceback.format_exc(5))
+
run = True
@@ -35,13 +70,18 @@ print 'Loading modules...'
modman = ModuleManager(config)
-connection = XMPPConnection(config, modman)
-print 'Connecting...'
-connection.connect()
-
while run:
- act = connection.stream.loop_iter(1)
- if not act:
- connection.idle()
-
-connection.disconnect()
+ connection = XMPPConnection(config, modman)
+ print 'Connecting...'
+ connection.connect()
+
+ try:
+ while run:
+ act = connection.stream.loop_iter(1)
+ if not act:
+ connection.idle()
+
+ connection.disconnect()
+ except:
+ traceback.print_exc(file=sys.stdout)
+ connection.disconnect()