Fix bot event loop

master
Nikola Forró 6 years ago
parent 8270f8e183
commit 15a659cfd1

@ -37,22 +37,30 @@ def main():
commands = Commands(config, commands_logger)
discord_client = DiscordClient(config, discord_logger, commands)
async def run_twitch_client():
twitch_client = TwitchClient(config, twitch_logger, commands)
twitch_client.connect_()
while True:
twitch_client.process_data()
await asyncio.sleep(TIMEOUT)
asyncio.ensure_future(run_twitch_client())
try:
twitch_client.process_data()
await asyncio.sleep(TIMEOUT)
except Exception as e:
twitch_logger.info('Exception', exc_info=e)
async def run_discord_client():
discord_client = DiscordClient(config, discord_logger, commands)
while True:
try:
await discord_client.start_()
except Exception as e:
discord_logger.info('Exception', exc_info=e)
await discord_client.logout()
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(discord_client.start_())
except:
loop.run_until_complete(discord_client.logout())
asyncio.ensure_future(run_twitch_client())
asyncio.ensure_future(run_discord_client())
loop.run_forever()
finally:
loop.close()

Loading…
Cancel
Save