2019-02-02 16:20:32 +00:00
|
|
|
import asyncio
|
2019-01-04 16:54:38 +00:00
|
|
|
from sys import stdout
|
2019-01-14 20:20:16 +00:00
|
|
|
from GeoffreyBot.geoffrey import *
|
2019-01-04 16:54:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_logging():
|
|
|
|
discord_logger = logging.getLogger('discord')
|
|
|
|
discord_logger.setLevel(logging.INFO)
|
2019-01-14 20:20:16 +00:00
|
|
|
bot_info_logger = logging.getLogger('GeoffreyBot')
|
2019-01-04 16:54:38 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2019-01-14 20:20:16 +00:00
|
|
|
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-01-04 16:54:38 +00:00
|
|
|
|
2019-02-02 16:20:32 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
|
|
|
|
try:
|
|
|
|
loop.run_until_complete(bot.start(discord_token))
|
2019-01-04 16:54:38 +00:00
|
|
|
|
|
|
|
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())
|
2019-01-04 16:54:38 +00:00
|
|
|
logger.info("Bot shutting down...")
|