Geoffrey-Bot/GeoffreyBot/bot.py

37 lines
1.1 KiB
Python

import asyncio
from sys import stdout
from GeoffreyBot.geoffrey import *
def setup_logging():
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.INFO)
bot_info_logger = logging.getLogger('GeoffreyBot')
bot_info_logger.setLevel(logging.INFO)
console = logging.StreamHandler(stdout)
console.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
bot_info_logger.addHandler(console)
def start_bot(discord_token, geoffrey_api_token, geoffrey_base_url):
setup_logging()
loop = None
bot = None
try:
bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token)
loop = asyncio.get_event_loop()
loop.run_until_complete(bot.start(discord_token))
except KeyboardInterrupt:
logger.info("Bot received keyboard interrupt")
except Exception as e:
print(e)
logger.info('Bot encountered the following unhandled exception %s', e)
finally:
if loop and bot:
loop.run_until_complete(bot.logout())
logger.info("Bot shutting down...")