From f5a61e02c0d0d283d11b6e82dcb871ca01f40074 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sat, 2 Feb 2019 10:20:32 -0600 Subject: [PATCH] Cleaned up errors on shutdown --- GeoffreyBot/bot.py | 13 ++++++++----- GeoffreyBot/geoffrey.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/GeoffreyBot/bot.py b/GeoffreyBot/bot.py index 307f1be..8eabb74 100644 --- a/GeoffreyBot/bot.py +++ b/GeoffreyBot/bot.py @@ -1,5 +1,5 @@ +import asyncio from sys import stdout - from GeoffreyBot.geoffrey import * @@ -15,11 +15,13 @@ def setup_logging(): def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url): - try: - setup_logging() - bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token) + setup_logging() + bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token) - bot.run(discord_token) + loop = asyncio.get_event_loop() + + try: + loop.run_until_complete(bot.start(discord_token)) except KeyboardInterrupt: logger.info("Bot received keyboard interrupt") @@ -27,4 +29,5 @@ def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url): print(e) logger.info('Bot encountered the following unhandled exception %s', e) finally: + loop.run_until_complete(bot.logout()) logger.info("Bot shutting down...") diff --git a/GeoffreyBot/geoffrey.py b/GeoffreyBot/geoffrey.py index 1bb9e8a..4973e17 100644 --- a/GeoffreyBot/geoffrey.py +++ b/GeoffreyBot/geoffrey.py @@ -62,7 +62,6 @@ class GeoffreyBot(commands.Bot): await self.change_presence(activity=Game(self.default_status)) async def on_command(self, ctx): - URL = self.base_url + '/api/command/{}' if ctx.invoked_subcommand is None: subcommand = "" else: @@ -177,3 +176,4 @@ class GeoffreyBot(commands.Bot): help_dict[command_name] = help_list return help_dict +