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.bot, 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 __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 __init__(self, bot): self.bot = bot self.username = self.bot.nickname self.password = self.bot.password self.channels = [] self.channel = "#" + self.bot.streamer self.channels.append(self.channel) self.control_hub_channel = self.bot.config["main"].get( "control_hub", None) if self.control_hub_channel: self.control_hub_channel = "#" + self.control_hub_channel self.channels.append(self.control_hub_channel) chub = bot.config["main"].get("control_hub", "") self.connection_manager = ConnectionManager( self.bot.reactor, self.bot, streamer=self.bot.streamer, control_hub_channel=chub, host="irc.chat.twitch.tv", port=6697, )
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"))
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()
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()
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()
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'))
class IRCManager: def __init__(self, bot): self.bot = bot self.channels = [] self.channel = "#" + self.bot.streamer self.channels.append(self.channel) self.control_hub_channel = self.bot.config["main"].get( "control_hub", None) if self.control_hub_channel: self.control_hub_channel = "#" + self.control_hub_channel self.channels.append(self.control_hub_channel) chub = bot.config["main"].get("control_hub", "") self.connection_manager = ConnectionManager( self.bot.reactor, self.bot, streamer=self.bot.streamer, control_hub_channel=chub, host="irc.chat.twitch.tv", port=6697, ) def start(self): self.connection_manager.start() def whisper(self, username, message): self.connection_manager.privmsg(f"#{self.bot.nickname}", f"/w {username} {message}", whisper=True) def privmsg(self, message, channel, increase_message=True): self.connection_manager.privmsg(channel, message, increase_message=increase_message) def on_disconnect(self, chatconn, event): self.connection_manager.on_disconnect(chatconn) def _dispatcher(self, connection, event): method = getattr(self.bot, "on_" + event.type, do_nothing) try: method(connection, event) except: log.exception("Logging an uncaught exception (IRC event handler)") def on_welcome(self, conn, event): log.info("Successfully connected and authenticated with IRC") conn.join(",".join(self.channels)) def on_connect(self, sock): pass
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()