Ejemplo n.º 1
0
class AQBot:
    raw_log = None
    error_log = None

    socket = None
    messenger = None

    network = None
    channel = None

    command_manager = None
    plugin_manager = None

    def __init__(self, network, channel):
        self.raw_log = Logger('aqbot_raw.log')
        self.error_log = Logger('aqbot_error.log')
        sys.excepthook = self.error_log.exception

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.messenger = irc_messenger.Messenger(self.socket)

        self.network = irc_network.Network(network)
        self.channel = irc_channel.Channel(channel)

        self.network.connect(self.socket)
        self.network.login(self.messenger)
        self.channel.join(self.messenger)

        self.command_manager = cmd_manager.CommandManager(self)
        self.plugin_manager = plug_manager.PluginManager(self)
        self.messenger.set_bot(self)

        try:
            self.plugin_manager.scan()
        except:
            self.error_log.log("error", __file__, "Uncaught Exception: %s!" % sys.exc_info()[0])
            pass

        try:
            self.plugin_manager.load_plugins(self.channel.plugins)
        except:
            self.error_log.log("error", __file__, "Uncaught Exception: %s!" % sys.exc_info()[0])
            pass

        self._listen()

    def _listen(self):
        p = multiprocessing.Process(target=self._loop)
        p.start()

    def _loop(self):
        while self.network.connected:
            self.messenger.send()
            self.messenger.recvbuff()
            self.messenger.recv()
Ejemplo n.º 2
0
class DatabaseManager(object):
    raw_log = None
    error_log = None

    def __init__(self):
        self.raw_log = Logger('db/aqbot_raw.log')
        self.error_log = Logger('db/aqbot_error.log')
        sys.excepthook = self.error_log.exception
        self.raw_log.log("debug", __file__, "DatabaseManager started!")

    def connect(self):
        cur = sqlite3.connect(self.filename).cursor()