Added stubs for classes and cogs, performed a cleanup, added more database indexes

This commit is contained in:
2025-04-18 00:48:09 +02:00
parent 82c57a3dd1
commit 691dd1c958
9 changed files with 104 additions and 23 deletions

30
main.py
View File

@@ -1,16 +1,16 @@
import asyncio
import contextlib
import logging.config
from argparse import ArgumentParser
from logging import Logger
from os import getpid, makedirs
from os import makedirs
from pathlib import Path
from sys import exit
# Import required for uvicorn
from discord import LoginFailure
from libbot.utils import config_get
from classes.pycord_bot import PycordBot
from modules.logging_utils import get_logging_config, get_logger
from modules.logging_utils import get_logger, get_logging_config
from modules.migrator import migrate_database
from modules.scheduler import scheduler
@@ -21,9 +21,7 @@ logging.config.dictConfig(get_logging_config())
logger: Logger = get_logger(__name__)
# Declare the parser that retrieves the command line arguments
parser: ArgumentParser = ArgumentParser(
prog="QuizBot"
)
parser: ArgumentParser = ArgumentParser(prog="QuizBot")
# Add a switch argument --migrate to be parsed...
parser.add_argument("--migrate", action="store_true")
@@ -41,7 +39,7 @@ with contextlib.suppress(ImportError):
uvloop.install()
async def main():
def main():
# Perform migration if command line argument was provided
if args.migrate:
migrate_database()
@@ -57,16 +55,22 @@ async def main():
# downgrade_database()
# exit()
bot = PycordBot(scheduler=scheduler)
bot: PycordBot = PycordBot(scheduler=scheduler)
bot.load_extension("cogs")
try:
await bot.start(config_get("bot_token", "bot"))
bot.run(config_get("bot_token", "bot"))
except LoginFailure as exc:
logger.error("Provided bot token is invalid: %s", exc)
except KeyboardInterrupt:
logger.warning("Forcefully shutting down with PID %s...", getpid())
await bot.close()
logger.info("KeyboardInterrupt received: Shutting down gracefully.")
except Exception as exc:
logger.error("An unexpected error has occurred: %s", exc, exc_info=exc)
exit(1)
finally:
exit()
if __name__ == "__main__":
asyncio.create_task(main())
main()