Files
Javelina/main.py
2025-06-07 21:06:16 +02:00

57 lines
1.4 KiB
Python

import asyncio
import contextlib
import logging.config
from asyncio import get_event_loop
from logging import Logger
from os import getpid, makedirs
from pathlib import Path
from sys import exit
from discord import LoginFailure
from libbot.utils import config_get
# Import required for uvicorn
from api.app import app # noqa
from classes.pycord_bot import PycordBot
from modules.scheduler import scheduler
from modules.utils import get_logger, get_logging_config
makedirs(Path("logs/"), exist_ok=True)
logging.config.dictConfig(get_logging_config())
logger: Logger = get_logger(__name__)
# Try to import the module that improves performance
# and ignore errors when module is not installed
with contextlib.suppress(ImportError):
import uvloop
uvloop.install()
async def main():
bot: PycordBot = PycordBot(scheduler=scheduler)
bot.load_extension("cogs")
app.set_bot(bot)
try:
await bot.start(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()
except Exception as exc:
logger.error("An unexpected error has occurred: %s", exc, exc_info=exc)
exit(1)
asyncio.create_task(main())
if __name__ == "__main__":
event_loop = get_event_loop()
event_loop.run_until_complete(main())