Ejemplo n.º 1
0
    def __init__(self, botconfig):
        """Setup everything."""
        if botconfig.getboolean('core', 'ssl'):
            factory = connection.Factory(wrapper=ssl.wrap_socket, ipv6=botconfig.getboolean('core', 'ipv6'))
        else:
            factory = connection.Factory(ipv6=botconfig.getboolean('core', 'ipv6'))
        passwd = None if botconfig.getboolean('core', 'sasl') else botconfig['auth']['serverpass']
        serverinfo = bot.ServerSpec(botconfig['core']['host'], botconfig.getint('core', 'ircport'), passwd)
        nick = botconfig['core']['nick']
        super().__init__([serverinfo], nick, nick, connect_factory=factory, reconnection_interval=5)
        # This does the magic when everything else is dead
        self.connection.add_global_handler("pubmsg", self.reload_handler, -30)
        self.connection.add_global_handler("all_events", self.handle_event, 10)
        # We need to get the channels that a nick is currently in before the regular quit event is processed.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        if passwd is None:
            # FIXME: make this less hacky
            self.reactor._on_connect = self.do_sasl
        self.config = botconfig
        self.handler = handler.BotHandler(botconfig, self.connection, self.channels)
        if not reloader.load_modules(botconfig):
            # The initial load of commands/hooks failed, so bail out.
            self.shutdown_mp(False)
            sys.exit(1)
        self.event_queue = queue.Queue()
        # Are we running in bare-bones, reload-only mode?
        self.reload_event = threading.Event()

        if botconfig['feature'].getboolean('server'):
            self.server = server.init_server(self)
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'
Ejemplo n.º 2
0
Archivo: core.py Proyecto: tjcsl/cslbot
    def __init__(self, confdir, config, spec, idx):
        """Setup everything."""
        signal.signal(signal.SIGTERM, self.shutdown)
        self.confdir = confdir
        self.config = config
        self.idx = idx
        if self.config.getboolean('core', 'ssl'):
            factory = connection.Factory(wrapper=ssl.wrap_socket, ipv6=self.config.getboolean('core', 'ipv6'))
        else:
            factory = connection.Factory(ipv6=self.config.getboolean('core', 'ipv6'))
        nick = self.config['core']['nick']
        self.reactor_class = functools.partial(client.Reactor, on_connect=self.do_cap)
        super().__init__([spec], nick, nick, connect_factory=factory)
        # These allow reload events to be processed when a reload has failed.
        self.connection.add_global_handler("pubmsg", self.reload_handler, -30)
        self.connection.add_global_handler("privmsg", self.reload_handler, -30)
        self.connection.add_global_handler("all_events", self.handle_event, 10)
        # We need to get the channels that a nick is currently in before the regular quit event is processed and the nick is removed from self.channels.
        self.connection.add_global_handler("quit", self.handle_quit, -21)
        self.event_queue = queue.Queue()
        # Are we running in bare-bones, reload-only mode?
        self.reload_event = threading.Event()
        # fix unicode problems
        self.connection.buffer_class.errors = 'replace'

        if not reloader.load_modules(self.config, confdir):
            raise Exception("Failed to load modules.")

        self.handler = handler.BotHandler(self.config, self.connection, self.channels, confdir, self.idx)
        if self.config['feature'].getboolean('server'):
            self.server = server.init_server(self)
Ejemplo n.º 3
0
 def on_disconnect(self, _connection, _event):
     """Attempt to reconnect after disconnection."""
     self.log.info("Disconnected from %s:%d" % (self.server, self.port))
     self.log.info("Reconnecting in %d seconds" % self.reconnect_delay)
     time.sleep(self.reconnect_delay)
     self.log.info("Connecting to %s:%d as %s" %
                   (self.server, self.port, self.nick))
     self.connect(self.server,
                  self.port,
                  self.nick,
                  self.password,
                  username=self.username,
                  connect_factory=connection.Factory(
                      wrapper=ssl.wrap_socket, ipv6=self.ipv6).connect
                  if self.ssl else connection.Factory())
Ejemplo n.º 4
0
    def __init__(self,
                 db_url,
                 server,
                 port,
                 channels,
                 nickname,
                 password,
                 darkchannels,
                 server_password=None,
                 web_url=None):
        if port == 6697:
            factory = connection.Factory(wrapper=ssl.wrap_socket)
            super(PurplerBot, self).__init__([(server, port, server_password)],
                                             nickname,
                                             nickname,
                                             connect_factory=factory)
        else:
            super(PurplerBot, self).__init__([(server, port, server_password)],
                                             nickname, nickname)

        self.channel_list = channels
        self.darkchannels = darkchannels
        self.nickname = nickname
        self.password = password
        self.web_url = web_url
        self.log = logging.getLogger(__name__)
        self.storage = store.Store(db_url)
Ejemplo n.º 5
0
def main():
    logging.basicConfig(level=logging.INFO)
    config = configparser.ConfigParser(
        interpolation=configparser.ExtendedInterpolation())
    with open('config.cfg') as f:
        config.read_file(f)
    CTRLNICK = "bot-controller"
    client = IrcClient(CTRLNICK, config)
    if config.getboolean('core', 'ssl'):
        factory = connection.Factory(wrapper=ssl.wrap_socket,
                                     ipv6=config.getboolean('core', 'ipv6'))
    else:
        factory = connection.Factory(ipv6=config.getboolean('core', 'ipv6'))
    client.connect(config['core']['host'],
                   config.getint('core', 'ircport'),
                   CTRLNICK,
                   config['auth']['serverpass'],
                   connect_factory=factory)
    client.start()
Ejemplo n.º 6
0
def main() -> None:
    logging.basicConfig(level=logging.INFO)
    config = configparser.ConfigParser(
        interpolation=configparser.ExtendedInterpolation())
    with open('config.cfg') as f:
        config.read_file(f)
    ctrl_nick = "bot-controller"
    ircclient = IrcClient(ctrl_nick, config)
    if config.getboolean('core', 'ssl'):
        factory = connection.Factory(wrapper=ssl.wrap_socket,
                                     ipv6=config.getboolean('core', 'ipv6'))
    else:
        factory = connection.Factory(ipv6=config.getboolean('core', 'ipv6'))
    for host in config['core']['host'].split(','):
        ircclient.connect(host.strip(),
                          config.getint('core', 'ircport'),
                          ctrl_nick,
                          config['auth']['serverpass'],
                          connect_factory=factory)
        ircclient.start()
Ejemplo n.º 7
0
    def __init__(self, network):
        irclib.SimpleIRCClient.__init__(self)

        pyhole_config = utils.get_config()
        network_config = utils.get_config(network)

        self.log = logger.get_logger(str(network))
        self.version = version.version_string()
        self.source = None
        self.target = None
        self.addressed = False

        self.admins = pyhole_config.get("admins", type="list")
        self.command_prefix = pyhole_config.get("command_prefix")
        self.reconnect_delay = pyhole_config.get("reconnect_delay", type="int")
        self.rejoin_delay = pyhole_config.get("rejoin_delay", type="int")

        self.server = network_config.get("server")
        self.password = network_config.get("password", default=None)
        self.port = network_config.get("port", type="int", default=6667)
        self.ssl = network_config.get("ssl", type="bool", default=False)
        self.ipv6 = network_config.get("ipv6", type="bool", default=False)
        self.bind_to = network_config.get("bind_to", default=None)
        self.nick = network_config.get("nick")
        self.username = network_config.get("username", default=None)
        self.identify_password = network_config.get("identify_password",
                                                    default=None)
        self.channels = network_config.get("channels", type="list")

        self.load_plugins()

        self.log.info("Connecting to %s:%d as %s" %
                      (self.server, self.port, self.nick))
        self.connect(self.server,
                     self.port,
                     self.nick,
                     self.password,
                     username=self.username,
                     connect_factory=connection.Factory(
                         wrapper=ssl.wrap_socket, ipv6=self.ipv6).connect
                     if self.ssl else connection.Factory())
Ejemplo n.º 8
0
    def __init__(self):
        if not IRC.is_configured():
            raise RuntimeError('IRCDaemon is not configured')
        if os.path.exists(settings.IRC_SOCKET_PATH):
            os.remove(settings.IRC_SOCKET_PATH)
        self.is_alive = False

        self.get_msg = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
        self.get_msg.bind(settings.IRC_SOCKET_PATH)

        self.client = IRCClient()
        for conf in settings.IRC:
            try:
                server = self.client.server()
                server.gandi_conf = conf

                for elem in dir(self):
                    if elem.startswith('on_'):
                        server.add_global_handler(elem[3:],
                                                  getattr(self, elem))

                if conf.get('ssl', False):
                    connection_factory = connection.Factory(
                        wrapper=ssl.wrap_socket)
                else:
                    connection_factory = connection.Factory()
                server.connect(conf.get('server'), conf.get('port', 6667),
                               conf.get('nick'), conf.get('password'),
                               conf.get('username'), conf.get('ircname'),
                               connection_factory)

            except ServerConnectionError as err:
                LOG.error(err)

        signal.signal(signal.SIGINT, self.shutdown)
        signal.signal(signal.SIGQUIT, self.shutdown)
        signal.signal(signal.SIGTERM, self.shutdown)
Ejemplo n.º 9
0
    LOG = logging.getLogger('kabasbot-irc')
    LOG.setLevel(logging.DEBUG)
    logging.basicConfig(level=logging.DEBUG)
    handler = RotatingFileHandler('irc.log',
                                  mode='a',
                                  maxBytes=10 * 1024 * 1024,
                                  backupCount=100)
    formatter = logging.Formatter('%(asctime)-15s:%(levelname)-6s:%(message)s',
                                  '%Y.%m.%d-%I:%M:%s')
    handler.setFormatter(formatter)
    handler.setLevel(logging.DEBUG)
    LOG.addHandler(handler)

    # Override other library logging
    ROOTLOG = logging.getLogger()
    ROOTLOG.addHandler(handler)

    settings = KABASConfig("kabasbot-irc.cfg")

    if settings.ssl:
        wrapper = ssl.wrap_socket
    else:
        wrapper = connection.identity

    bot = KABASBot(settings=settings,
                   connect_factory=connection.Factory(
                       bind_address=(settings.bindaddr, 0),
                       ipv6=settings.ipv6,
                       wrapper=wrapper))
    bot.start()