#!/usr/bin/env python import sys sys.path.append('./irclib-0.3.1') import ircbot import Config import os import glob import imp from types import ClassType from irclib import nm_to_n, nm_to_uh VERSION="benzo-0.3 http://www.sourceforge.net/projects/benzo" class Benzo(ircbot.SingleServerIRCBot): def __init__(self): self.version = VERSION self.config = Config # this is hackish - find away for events to expose this themselves self.nm_to_n = nm_to_n self.nm_to_uh = nm_to_uh ircbot.SingleServerIRCBot.__init__(self, self.config.SERVER_LIST, self.config.NICKNAME, self.config.REALNAME) self.event_dict = {} # dict of event->(priority, handler) self.modules = {} # dict of handler modules self.interfaces = {} # dict of module-provided interfaces self.init_modules() self.connection.add_global_handler("all_events", self.dispatcher, -10) def dispatcher(self, connection, event): """ dispatch events to handlers. """ # TODO: abstract away from the irclib 'event' and 'connection classes # to provide a more high-level interface to modules. pubmsg # and privmsg are 99% of what this bot deals with, so make those # easy to work with # lets not doubly dispatch events if event.eventtype() == "all_raw_messages": return if self.event_dict.has_key(event.eventtype()): handler_list = self.event_dict[event.eventtype()] # sort the handler list by priority - lowest wins handler_list.sort() print "Got %d handlers for %s" % (len(handler_list), on and on