def main(): config = configparser.ConfigParser() config.read('config.ini') username = config['twitch']['username'] client_id = config['twitch']['client_id'] token = config['twitch']['token'] channel = config['twitch']['channel'] reward_id = config['twitch']['reward_id'] devices = config['homeassistant']['devices'] auth_key = config['homeassistant']['auth_key'] url = config['homeassistant']['url'] # print(username) # print(client_id) # print(token) # print(channel) # print(devices) # print(auth_key) # print(url) homeassistant = HomeAssistant(devices, url, auth_key) bot = TwitchBot(username, client_id, token, channel, reward_id, homeassistant) bot.start()
class twitchBotThread(QtCore.QThread): def __init__(self, parent, ident, session, running=True, failureThreshold=5): super(twitchBotThread, self).__init__(parent) self.parent = parent self.id = ident self.session = session self.running = running self.failureThreshold = failureThreshold # Bind parent event for talking through us to chat room QtCore.QObject.connect(self.parent, QtCore.SIGNAL("sendIRCMessageToRoom"), self.talk) def stop(self): self.running = False def run(self): failures = 0 while self.running: try: self._run() except: failures += 1 if failures > self.failureThreshold: self.running = False else: self.emit(QtCore.SIGNAL("botThreadPartialFailure"), failures, self.failureThreshold) time.sleep(1) else: self.running = False def _run(self): ''' Main function of thread. Runs the twitch bot main loop ''' try: # Build and run bot in _run, so failures in both commands can be caught in failure threshold logic self.bot = TwitchBot(self, self.session['channel'], self.session['nickname'], self.session['server'], self.session['port'], self.session['password']) self.bot.start() except Exception, e: print str(e)
def _create_bot(self, name, channels): conn = IRCConnection(settings.IRC['SERVER'], settings.IRC['PORT'], settings.IRC['NICK'], settings.IRC['PASSWORD'], self.log_filename) bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'], settings.DATABASE['NAME'], settings.DATABASE['USER'], settings.DATABASE['PASSWORD']) bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename) bot.daemon = True bot.connect_and_join_channels(channels) bot.start() return bot
def _create_bot(self, name, channels): conn = IRCConnection(settings.IRC['SERVER'], settings.IRC['PORT'], settings.IRC['NICK'], settings.IRC['PASSWORD'], self.log_filename) bot_db_logger = DatabaseLogger(settings.DATABASE['HOST'], settings.DATABASE['NAME'], settings.DATABASE['USER'], settings.DATABASE['PASSWORD']) bot = TwitchBot(name, conn, bot_db_logger, Queue.Queue(), self.log_filename) bot.daemon = True bot.connect_and_join_channels(channels) bot.start() return bot