update du bot pour illustrer la prod
This commit is contained in:
parent
1b02dd8b22
commit
093b190f08
1 changed files with 26 additions and 19 deletions
37
bot.py
37
bot.py
|
|
@ -1,24 +1,28 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from config import DISCORD_TOKEN
|
from config import DISCORD_TOKEN
|
||||||
|
|
||||||
# Import des managers
|
|
||||||
from utils.DatabaseManager_class import DatabaseManager
|
from utils.DatabaseManager_class import DatabaseManager
|
||||||
from utils.ScreenshotManager_class import ScreenshotManager
|
from utils.ScreenshotManager_class import ScreenshotManager
|
||||||
|
from utils.MercyManager_class import MercyManager
|
||||||
|
from utils.pb_handler import set_managers
|
||||||
|
from utils.leaderboard_handler import set_db_manager
|
||||||
|
|
||||||
# Définir les intents
|
# Définir les intents
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix="!", intents=intents)
|
# Initialisation des managers
|
||||||
|
|
||||||
# Initialisation unique des managers
|
|
||||||
db_manager = DatabaseManager()
|
db_manager = DatabaseManager()
|
||||||
screenshot_manager = ScreenshotManager()
|
screenshot_manager = ScreenshotManager()
|
||||||
|
mercy_manager = MercyManager()
|
||||||
|
|
||||||
# Liste des Cogs à charger
|
# Injection des managers dans les handlers
|
||||||
|
set_managers(db_manager, screenshot_manager) # pb_handler
|
||||||
|
set_db_manager(db_manager) # leaderboard_handler
|
||||||
|
|
||||||
|
# Liste des cogs
|
||||||
initial_cogs = [
|
initial_cogs = [
|
||||||
"cogs.guide",
|
"cogs.guide",
|
||||||
"cogs.pbhydra",
|
"cogs.pbhydra",
|
||||||
|
|
@ -29,20 +33,23 @@ initial_cogs = [
|
||||||
"cogs.mercy",
|
"cogs.mercy",
|
||||||
]
|
]
|
||||||
|
|
||||||
async def load_cogs():
|
class MyBot(commands.Bot):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(command_prefix="!", intents=intents)
|
||||||
|
self.db_manager = db_manager
|
||||||
|
self.screenshot_manager = screenshot_manager
|
||||||
|
self.mercy_manager = mercy_manager
|
||||||
|
|
||||||
|
async def setup_hook(self):
|
||||||
for cog in initial_cogs:
|
for cog in initial_cogs:
|
||||||
try:
|
try:
|
||||||
await bot.load_extension(cog)
|
await self.load_extension(cog)
|
||||||
print(f"[OK] Cog {cog} chargé")
|
print(f"[OK] Cog {cog} chargé")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ERREUR] Impossible de charger {cog}: {e}")
|
print(f"[ERREUR] Impossible de charger {cog}: {e}")
|
||||||
|
|
||||||
@bot.event
|
async def on_ready(self):
|
||||||
async def on_ready():
|
print(f"{self.user.name} est connecté !")
|
||||||
print(f"{bot.user.name} est connecté !")
|
|
||||||
|
|
||||||
# Charger les cogs avant le run
|
bot = MyBot()
|
||||||
bot.loop.create_task(load_cogs())
|
|
||||||
|
|
||||||
# Lancer le bot
|
|
||||||
bot.run(DISCORD_TOKEN)
|
bot.run(DISCORD_TOKEN)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue