Exemple #1
0
class MultiIRCManager(IRCManager):
    def __init__(self, bot):
        super().__init__(bot)

        self.connection_manager = ConnectionManager(self.bot.reactor, self.bot, TMI.message_limit, streamer=self.bot.streamer)
        chub = self.bot.config['main'].get('control_hub', None)
        if chub is not None:
            self.control_hub = ConnectionManager(self.bot.reactor, self.bot, TMI.message_limit, streamer=chub, backup_conns=1)
            log.info('start pls')
        else:
            self.control_hub = None

        # XXX
        self.bot.execute_every(30, lambda: self.connection_manager.get_main_conn().ping('tmi.twitch.tv'))

        self.whisper_manager = WhisperConnectionManager(self.bot.reactor, self, self.bot.streamer, TMI.whispers_message_limit, TMI.whispers_limit_interval)
        self.whisper_manager.start(accounts=[{'username': self.username, 'oauth': self.password, 'can_send_whispers': self.bot.config.getboolean('main', 'add_self_as_whisper_account')}])

    def whisper(self, username, message):
        if self.whisper_manager:
            self.whisper_manager.whisper(username, message)
        else:
            log.debug('No whisper conn set up.')

    def on_disconnect(self, chatconn, event):
        if chatconn in self.whisper_manager:
            log.debug('Whispers: Disconnecting from Whisper server')
            self.whisper_manager.on_disconnect(chatconn)
        else:
            log.debug('Disconnected from IRC server')
            self.connection_manager.on_disconnect(chatconn)

    def _dispatcher(self, connection, event):
        if connection == self.connection_manager.get_main_conn() or connection in self.whisper_manager or (self.control_hub is not None and connection == self.control_hub.get_main_conn()):
            method = getattr(self.bot, 'on_' + event.type, do_nothing)
            method(connection, event)

    def privmsg(self, message, channel, increase_message=True):
        try:
            if self.control_hub is not None and self.control_hub.channel == channel:
                self.control_hub.privmsg(channel, message)
            else:
                self.connection_manager.privmsg(channel, message, increase_message=increase_message)
        except Exception:
            log.exception('Exception caught while sending privmsg')

    def start(self):
        log.info('STARTING :)')
        self.connection_manager.start()
        log.info('ok')

    def quit(self):
        if self.whisper_manager:
            self.whisper_manager.quit()
Exemple #2
0
class MultiIRCManager(IRCManager):
    def __init__(self, bot):
        super().__init__(bot)

        chub = self.bot.config['main'].get('control_hub', '')
        self.connection_manager = ConnectionManager(self.bot.reactor, self.bot, streamer=self.bot.streamer, control_hub_channel=chub)

        # XXX
        self.bot.execute_every(30, lambda: self.connection_manager.get_main_conn().ping('tmi.twitch.tv'))

    def whisper(self, username, message):
        self.connection_manager.privmsg('#jtv', '/w {} {}'.format(username, message))

    def on_disconnect(self, chatconn, event):
        log.debug('Disconnected from IRC server')
        self.connection_manager.on_disconnect(chatconn)

    def _dispatcher(self, connection, event):
        method = getattr(self.bot, 'on_' + event.type, do_nothing)
        method(connection, event)

    def privmsg(self, message, channel, increase_message=True):
        try:
            self.connection_manager.privmsg(channel, message, increase_message=increase_message)
        except Exception:
            log.exception('Exception caught while sending privmsg')

    def start(self):
        self.connection_manager.start()
Exemple #3
0
class MultiIRCManager(IRCManager):
    def __init__(self, bot):
        super().__init__(bot)

        chub = self.bot.config["main"].get("control_hub", "")
        self.connection_manager = ConnectionManager(
            self.bot.reactor, self.bot, streamer=self.bot.streamer, control_hub_channel=chub
        )

        # XXX
        self.bot.execute_every(30, lambda: self.connection_manager.get_main_conn().ping("tmi.twitch.tv"))

    def whisper(self, username, message):
        self.connection_manager.privmsg("#{}".format(self.bot.nickname), "/w {} {}".format(username, message))

    def on_disconnect(self, chatconn, event):
        log.debug("Disconnected from IRC server")
        self.connection_manager.on_disconnect(chatconn)

    def _dispatcher(self, connection, event):
        method = getattr(self.bot, "on_" + event.type, do_nothing)
        method(connection, event)

    def privmsg(self, message, channel, increase_message=True):
        try:
            self.connection_manager.privmsg(channel, message, increase_message=increase_message)
        except Exception:
            log.exception("Exception caught while sending privmsg")

    def start(self):
        self.connection_manager.start()
Exemple #4
0
class MultiIRCManager(IRCManager):
    def __init__(self, bot):
        super().__init__(bot)

        self.connection_manager = ConnectionManager(
            self.bot.reactor, self.bot, TMI.message_limit, streamer=self.bot.streamer
        )
        chub = self.bot.config["main"].get("control_hub", None)
        if chub is not None:
            self.control_hub = ConnectionManager(
                self.bot.reactor, self.bot, TMI.message_limit, streamer=chub, backup_conns=1
            )
        else:
            self.control_hub = None

        # XXX
        self.bot.execute_every(30, lambda: self.connection_manager.get_main_conn().ping("tmi.twitch.tv"))

        self.whisper_manager = WhisperConnectionManager(
            self.bot.reactor, self, self.bot.streamer, TMI.whispers_message_limit, TMI.whispers_limit_interval
        )
        self.whisper_manager.start(
            accounts=[
                {
                    "username": self.username,
                    "oauth": self.password,
                    "can_send_whispers": self.bot.config.getboolean("main", "add_self_as_whisper_account"),
                }
            ]
        )

    def whisper(self, username, message):
        if self.whisper_manager:
            self.whisper_manager.whisper(username, message)
        else:
            log.debug("No whisper conn set up.")

    def on_disconnect(self, chatconn, event):
        if chatconn in self.whisper_manager:
            log.debug("Whispers: Disconnecting from Whisper server")
            self.whisper_manager.on_disconnect(chatconn)
        else:
            log.debug("Disconnected from IRC server")
            self.connection_manager.on_disconnect(chatconn)

    def _dispatcher(self, connection, event):
        if (
            connection == self.connection_manager.get_main_conn()
            or connection in self.whisper_manager
            or (self.control_hub is not None and connection == self.control_hub.get_main_conn())
        ):
            method = getattr(self.bot, "on_" + event.type, do_nothing)
            method(connection, event)

    def privmsg(self, message, channel, increase_message=True):
        try:
            if self.control_hub is not None and self.control_hub.channel == channel:
                self.control_hub.privmsg(channel, message)
            else:
                self.connection_manager.privmsg(channel, message, increase_message=increase_message)
        except Exception:
            log.exception("Exception caught while sending privmsg")

    def start(self):
        self.connection_manager.start()

    def quit(self):
        if self.whisper_manager:
            self.whisper_manager.quit()