Geoffrey-Bot/GeoffreyBot/bot.py

34 lines
1.0 KiB
Python
Raw Normal View History

2019-02-02 16:20:32 +00:00
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):
2019-02-02 16:20:32 +00:00
setup_logging()
bot = GeoffreyBot(geoffrey_base_url, geoffrey_api_token)
2019-02-02 16:20:32 +00:00
loop = asyncio.get_event_loop()
try:
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:
2019-02-02 16:20:32 +00:00
loop.run_until_complete(bot.logout())
logger.info("Bot shutting down...")