dj-embe/__main__.py
2023-05-06 03:25:01 +02:00

60 lines
1.5 KiB
Python

from os import mkdir, path
from discord import Bot, Intents
from toml import TomlDecodeError
from cog import Greetings, Music
from config import Config
from framework import Downloader, Redis, Spotify, Youtube
from logger import Logger
from service import FileManager, QueueManager
from usecase import Sources
if __name__ == "__main__":
# Read Config
try:
config = Config("config.toml")
except TomlDecodeError as error:
print("Config/DecodeError : %s" % error)
exit(1)
except KeyError as error:
print("Config/KeyError : %s" % error)
exit(2)
if not path.isdir(config.downloadDirectory):
mkdir(config.downloadDirectory)
# Set Logger
logger = Logger(config.logging)()
# Redis Client
redis = Redis(logger, config.redis, config.appName)
# Queue Manager
queueManager = QueueManager(redis)
# Bot Init
bot = Bot(intents=Intents.default())
# Youtube Client
youtube = Youtube(bot.loop, config.youtube, config.downloadDirectory)
# Spotify Client
spotify = Spotify(bot.loop, config.spotify)
# Downloader
downloader = Downloader(bot.loop)
# File Manager
fileManager = FileManager(youtube, downloader, config.downloadDirectory)
# Sources
sources = Sources(fileManager, youtube, spotify)
# Add Cogs
bot.add_cog(Greetings(bot, logger, redis))
bot.add_cog(Music(bot, logger, queueManager, sources))
# Run
bot.run(config.discord.token)