This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
curunir/curunir.py
2010-05-09 21:52:09 +02:00

87 lines
2.4 KiB
Python

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))
run = True
def exithandler(signum, frame):
global run
run = False
print 'Starting Curunir 0.1'
signal.signal(signal.SIGINT, exithandler)
signal.signal(signal.SIGTERM, exithandler)
signal.signal(signal.SIGQUIT, exithandler)
print 'Loading modules...'
modman = ModuleManager(config)
while run:
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()