Cleaned up errors on shutdown

master
Joey Hines 2019-02-02 10:20:32 -06:00
parent cb4a173508
commit f5a61e02c0
2 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import asyncio
from sys import stdout from sys import stdout
from GeoffreyBot.geoffrey import * from GeoffreyBot.geoffrey import *
@ -15,11 +15,13 @@ def setup_logging():
def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url): def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url):
try: setup_logging()
setup_logging() bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token)
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: except KeyboardInterrupt:
logger.info("Bot received keyboard interrupt") logger.info("Bot received keyboard interrupt")
@ -27,4 +29,5 @@ def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url):
print(e) print(e)
logger.info('Bot encountered the following unhandled exception %s', e) logger.info('Bot encountered the following unhandled exception %s', e)
finally: finally:
loop.run_until_complete(bot.logout())
logger.info("Bot shutting down...") logger.info("Bot shutting down...")

View File

@ -62,7 +62,6 @@ class GeoffreyBot(commands.Bot):
await self.change_presence(activity=Game(self.default_status)) await self.change_presence(activity=Game(self.default_status))
async def on_command(self, ctx): async def on_command(self, ctx):
URL = self.base_url + '/api/command/{}'
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
subcommand = "" subcommand = ""
else: else:
@ -177,3 +176,4 @@ class GeoffreyBot(commands.Bot):
help_dict[command_name] = help_list help_dict[command_name] = help_list
return help_dict return help_dict