76 lines
2.8 KiB
Python
76 lines
2.8 KiB
Python
from dotenv import load_dotenv
|
|
from os import getenv, listdir
|
|
|
|
from interactions import Client, Status
|
|
from pymongo import MongoClient # Used for database management
|
|
|
|
from gwendolyn.utils import log
|
|
from gwendolyn.exceptions import NoToken, CannotConnectToService
|
|
from gwendolyn.funcs import Other, BetterNetflix, Sonarr, Radarr, TMDb, QBittorrent
|
|
|
|
class Gwendolyn(Client):
|
|
def __init__(self, testing: bool = True):
|
|
"""Initialize the bot."""
|
|
initiation_parameters = {
|
|
"status": Status.DND,
|
|
"delete_unused_application_cmds": True
|
|
}
|
|
super().__init__(**initiation_parameters)
|
|
|
|
self.testing = testing
|
|
|
|
self._add_clients_and_options()
|
|
self._add_functions()
|
|
self._add_extensions()
|
|
|
|
def _add_clients_and_options(self):
|
|
"""Add all the client, option and credentials objects."""
|
|
load_dotenv()
|
|
self.bot_token = getenv("DISCORD_TOKEN")
|
|
|
|
if self.bot_token == "TOKEN":
|
|
raise NoToken()
|
|
|
|
self.admins = getenv("ADMINS").split(",")
|
|
|
|
mongo_user = getenv("MONGODB_USER")
|
|
mongo_password = getenv("MONGODB_PASSWORD")
|
|
mongo_url = f"mongodb+srv://{mongo_user}:{mongo_password}@gwendolyn"
|
|
mongo_url += ".qkwfy.mongodb.net/Gwendolyn?retryWrites=true&w=majority"
|
|
database_client = MongoClient(mongo_url)
|
|
|
|
try:
|
|
database_client.admin.command("ping")
|
|
self.log("Connected to Mango Client")
|
|
except:
|
|
raise CannotConnectToService("Mango Client")
|
|
|
|
if self.testing:
|
|
self.log("Testing mode")
|
|
self.database = database_client["Gwendolyn-Test"]
|
|
self.load_extension("interactions.ext.jurigged")
|
|
else:
|
|
self.database = database_client["Gwendolyn"]
|
|
|
|
def _add_functions(self):
|
|
self.other = Other(self)
|
|
self.better_netflix = BetterNetflix(
|
|
self,
|
|
radarr=Radarr(getenv("RADARR_IP"),getenv("RADARR_PORT"),getenv("RADARR_API_KEY")),
|
|
sonarr=Sonarr(getenv("SONARR_IP"),getenv("SONARR_PORT"),getenv("SONARR_API_KEY")),
|
|
tmdb=TMDb(getenv("TMDB_API_ACCESS_TOKEN")),
|
|
qbittorrent=QBittorrent(getenv("QBITTORRENT_IP"),getenv("QBITTORRENT_PORT"),getenv("QBITTORRENT_USERNAME"),getenv("QBITTORRENT_PASSWORD"))
|
|
)
|
|
|
|
def _add_extensions(self):
|
|
"""Load cogs."""
|
|
for filename in listdir("./gwendolyn/ext"):
|
|
if filename.endswith(".py"):
|
|
self.load_extension(f"gwendolyn.ext.{filename[:-3]}")
|
|
|
|
def log(self, messages, channel: str = "", level: int = 20): # pylint:disable=no-self-use
|
|
"""Log a message. Described in utils/util_functions.py."""
|
|
log(messages, channel, level)
|
|
|
|
def start(self):
|
|
super().start(self.bot_token) |