PYRSS-Bot/src/main.py

48 lines
1.2 KiB
Python

"""
Entry point for the application.
Run this file to get started.
"""
import logging
import asyncio
from os import getenv
from pathlib import Path
# it's important to load environment variables before
# importing the packages that depend on them.
from dotenv import load_dotenv
load_dotenv()
from bot import DiscordBot
from logs import LogSetup
BASE_DIR = Path(__file__).resolve().parent.parent
async def main():
"""
Entry point function for the application.
Run this function to get started.
"""
# Grab the token before anything else, because if there is no token
# available then the bot cannot be started anyways.
token = getenv("BOT_TOKEN")
if not token:
raise ValueError("Token is empty")
# Setup logging settings and mute spammy loggers
logsetup = LogSetup(BASE_DIR)
logsetup.setup_logs()
logsetup.update_log_levels(
('discord', 'PIL', 'urllib3', 'aiosqlite', 'charset_normalizer'),
level=logging.WARNING
)
async with DiscordBot(BASE_DIR) as bot:
await bot.load_extensions()
await bot.start(token, reconnect=True)
if __name__ == "__main__":
asyncio.run(main())