2020-10-13 21:02:40 +02:00
|
|
|
import discord
|
2021-06-14 23:33:53 +02:00
|
|
|
from discord.ext import commands, ipc
|
2020-10-13 21:02:40 +02:00
|
|
|
from dotenv import load_dotenv
|
2020-11-03 16:06:08 +01:00
|
|
|
from functions.prefixes import get_prefix
|
2020-10-13 21:02:40 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
2021-06-14 23:36:00 +02:00
|
|
|
# TODO pass option (bool) that launches IPC
|
|
|
|
# so there's no server running if it's not required
|
2021-06-14 23:33:53 +02:00
|
|
|
class Didier(commands.Bot):
|
|
|
|
"""
|
|
|
|
Main Bot class for Didier
|
|
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
# IPC Server
|
|
|
|
# TODO secret key
|
|
|
|
self.ipc = ipc.Server(self, secret_key="SOME_SECRET_KEY")
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
# Cogs that should be loaded before the others
|
|
|
|
self.preload = ("ipc", "utils", "failedchecks", "events",)
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
# Remove default help command
|
|
|
|
self.remove_command("help")
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
self.init_extensions()
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
def init_extensions(self):
|
|
|
|
# Load initial extensions
|
|
|
|
for ext in self.preload:
|
|
|
|
self.load_extension(f"cogs.{ext}")
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
# Load all remaining cogs
|
|
|
|
for file in os.listdir("./cogs"):
|
|
|
|
if file.endswith(".py") and not (file.startswith(self.preload)):
|
|
|
|
self.load_extension("cogs.{}".format(file[:-3]))
|
2020-10-13 21:02:40 +02:00
|
|
|
|
2021-06-14 23:33:53 +02:00
|
|
|
async def on_ipc_ready(self):
|
|
|
|
print("IPC server is ready.")
|
|
|
|
|
|
|
|
async def on_ipc_error(self, endpoint, error):
|
|
|
|
print(endpoint, "raised", error)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
load_dotenv(verbose=True)
|
|
|
|
|
|
|
|
# Configure intents (1.5.0)
|
|
|
|
intents = discord.Intents.default()
|
|
|
|
intents.members = True
|
|
|
|
|
|
|
|
client = Didier(command_prefix=get_prefix, case_insensitive=True, intents=intents)
|
|
|
|
|
|
|
|
# Get the token out of the file & run the bot
|
|
|
|
with open("files/client.txt", "r") as fp:
|
|
|
|
token = fp.readline()
|
|
|
|
|
|
|
|
client.ipc.start()
|
|
|
|
client.run(token)
|