2022-07-11 22:23:38 +02:00
|
|
|
import asyncio
|
2022-06-10 01:48:02 +02:00
|
|
|
import logging
|
2022-06-25 01:57:52 +02:00
|
|
|
import sys
|
2022-06-10 01:48:02 +02:00
|
|
|
from logging.handlers import RotatingFileHandler
|
|
|
|
|
|
|
|
import settings
|
2022-06-11 01:26:19 +02:00
|
|
|
from database.migrations import ensure_latest_migration
|
2022-06-10 01:48:02 +02:00
|
|
|
from didier import Didier
|
|
|
|
|
|
|
|
|
|
|
|
async def run_bot():
|
|
|
|
"""Run Didier"""
|
|
|
|
didier = Didier()
|
2022-11-02 01:32:06 +01:00
|
|
|
|
|
|
|
# Schedules are quite heavy - do this once before connecting
|
|
|
|
await didier.load_schedules()
|
|
|
|
|
2022-09-18 01:16:19 +02:00
|
|
|
try:
|
|
|
|
await didier.start(settings.DISCORD_TOKEN)
|
|
|
|
finally:
|
|
|
|
await didier.http_session.close()
|
2022-06-10 01:48:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def setup_logging():
|
|
|
|
"""Configure custom loggers"""
|
|
|
|
max_log_size = 32 * 1024 * 1024
|
|
|
|
|
2022-06-25 01:57:52 +02:00
|
|
|
# Configure Didier handler
|
2022-08-26 20:02:54 +02:00
|
|
|
didier_log = logging.getLogger(__name__)
|
2022-06-10 01:48:02 +02:00
|
|
|
|
2022-06-25 01:57:52 +02:00
|
|
|
didier_handler = RotatingFileHandler(settings.LOGFILE, mode="a", maxBytes=max_log_size, backupCount=5)
|
|
|
|
didier_handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s]: %(message)s"))
|
2022-06-10 01:48:02 +02:00
|
|
|
|
2022-06-25 01:57:52 +02:00
|
|
|
didier_log.addHandler(didier_handler)
|
2022-06-15 01:56:18 +02:00
|
|
|
didier_log.setLevel(logging.INFO)
|
2022-06-10 01:48:02 +02:00
|
|
|
|
2022-06-25 01:57:52 +02:00
|
|
|
# Configure discord handler
|
|
|
|
discord_log = logging.getLogger("discord")
|
|
|
|
|
|
|
|
# Make dev print to stderr instead, so you don't have to watch the file
|
|
|
|
if settings.SANDBOX:
|
|
|
|
discord_handler = logging.StreamHandler(sys.stderr)
|
|
|
|
else:
|
|
|
|
discord_handler = RotatingFileHandler("discord.log", mode="a", maxBytes=max_log_size, backupCount=5)
|
|
|
|
|
|
|
|
discord_handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s] %(name)s: %(message)s"))
|
|
|
|
discord_log.addHandler(discord_handler)
|
2022-06-10 01:48:02 +02:00
|
|
|
|
|
|
|
|
2022-06-11 01:26:19 +02:00
|
|
|
async def main():
|
|
|
|
"""Do some setup & checks, and then run the bot"""
|
2022-06-10 01:48:02 +02:00
|
|
|
setup_logging()
|
2022-06-11 01:26:19 +02:00
|
|
|
await ensure_latest_migration()
|
|
|
|
await run_bot()
|
|
|
|
|
2022-06-10 01:48:02 +02:00
|
|
|
|
2022-06-11 01:26:19 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.run(main())
|