56 lines
1.5 KiB
Python
56 lines
1.5 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 modules that depend on them.
|
|
from dotenv import load_dotenv
|
|
load_dotenv(override=True)
|
|
|
|
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.
|
|
bot_token = getenv("BOT_TOKEN")
|
|
if not bot_token:
|
|
raise ValueError("Bot Token is empty")
|
|
|
|
# ^ same story for the API token. Without it the API cannot be
|
|
# interacted with, so grab it first.
|
|
api_token = getenv("API_TOKEN")
|
|
if not api_token:
|
|
raise ValueError("API Token is empty")
|
|
|
|
developing = getenv("DEVELOPING", "False") == "True"
|
|
|
|
# Setup logging settings and mute spammy loggers
|
|
logsetup = LogSetup(BASE_DIR)
|
|
logsetup.setup_logs(logging.DEBUG if developing else logging.INFO)
|
|
logsetup.update_log_levels(
|
|
('discord', 'PIL', 'urllib3', 'aiosqlite', 'charset_normalizer'),
|
|
level=logging.WARNING
|
|
)
|
|
|
|
|
|
async with DiscordBot(BASE_DIR, developing=developing, api_token=api_token) as bot:
|
|
await bot.load_extensions()
|
|
await bot.start(bot_token, reconnect=True)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|