Пример #1
0
    def __init__(self, temp_folder):
        logging.basicConfig(filename="Bot.log", level=logging.DEBUG)

        self.settings = settings.load_settings()
        if not settings.validate_settings(self.settings):
            logging.error("Error parsing settings")
            sys.exit(1)
        self.plugins = list()
        self.servers = dict()
        self.temp_folder = temp_folder

        self.reactor = irc.client.Reactor()
        self.reactor.add_global_handler("all_events", self._dispatcher, -10)

        # Load plugins
        if 'plugins' in self.settings:
            for plugin_name, plugin_settings in self.settings['plugins'].items():
                self.load_plugin(plugin_name, plugin_settings)

        # Connect to servers
        servers = self.settings['servers']
        for server_name, server_settings in servers.items():
            logging.info("Connecting to %r %r", server_name, server_settings)
            s = self.reactor.server()
            self.servers[server_name] = s
            s.name = server_name
            s.buffer_class = jaraco.stream.buffer.LenientDecodingLineBuffer
            use_ssl = "ssl" in server_settings and server_settings["ssl"]
            factory = irc.connection.Factory(wrapper=ssl.wrap_socket) if use_ssl else irc.connection.Factory()
            s.connect(server_settings['host'], server_settings['port'], nickname=self.settings['nickname'],
                      ircname=self.settings['realname'], username=self.settings['username'],
                      connect_factory=factory)
Пример #2
0
 def test_validate_default_settings(self):
     setting = settings.DEFAULT_SETTINGS
     self.assertTrue(settings.validate_settings(setting))
Пример #3
0
        return Server(self._settings, self._plugins)

    def connected(self, name, server):
        log.msg("Bot.connected")
        server._name = name
        self._servers[name] = server

    def clientConnectionLost(self, connector, reason):
        log.msg("Bot.clientConnectionLost")
        connector.connect()

    def clientConnectionFailed(self, connector, reason):
        log.msg("Bot.clientConnectionFailed")
        reactor.stop()

if __name__ == '__main__':
    log.startLogging(open('Bot.log', 'a'))
    log.msg("main")
    config = settings.get_settings()
    if not settings.validate_settings(config):
        print("Error parsing settings")
        sys.exit(1)
    factory = Bot(config)
    for server in config['servers']:
        log.msg("main: creating endpoint for host:", server['host'], "port:", server['port'], "ssl:", server['ssl'])
        con_type = "ssl" if server['ssl'] else "tcp"
        con_desc = "{}:host={}:port={}".format(con_type, server['host'], server['port'])
        endpoint = endpoints.clientFromString(reactor, con_desc)
        conn = endpoint.connect(factory).addCallback(lambda s: factory.connected(server['name'], s))
    reactor.run()