From 22b3c2a3c42252c5530bc4cbc691c041d0c0fccd Mon Sep 17 00:00:00 2001 From: Mathis Date: Sat, 14 Mar 2026 17:56:26 +0100 Subject: [PATCH] =?UTF-8?q?V1.2=20du=20syst=C3=A8me=20de=20gestions=20des?= =?UTF-8?q?=20rapports=20d'utilisateur=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 29 +++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 30 insertions(+) diff --git a/bot.py b/bot.py index 45822f7..0348190 100755 --- a/bot.py +++ b/bot.py @@ -12,6 +12,8 @@ import asyncio from src.logger import kuby_logger, log_performance import logging from src.advanced_logger import AdvancedLogger +import subprocess +import sys # Récupération et validation de l'ID d'application application_id_raw = os.getenv("APPLICATION_ID") @@ -47,6 +49,23 @@ class MyBot(commands.Bot): self.advanced_logger = AdvancedLogger(self) kuby_logger.info("✅ Advanced logger initialized") + # Start the Flask Webhook Server + self.flask_process = None + try: + flask_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "serveur_flask.py") + if os.path.exists(flask_path): + self.flask_process = subprocess.Popen( + [sys.executable, flask_path], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=os.path.dirname(flask_path) + ) + kuby_logger.info(f"✅ Serveur Flask démarré (PID: {self.flask_process.pid})") + else: + kuby_logger.warning(f"⚠️ Fichier serveur_flask.py introuvable à {flask_path}") + except Exception as e: + kuby_logger.error(f"❌ Impossible de démarrer le serveur Flask: {e}") + # Charger les extensions extensions = [ "commandes.whitelist", @@ -130,6 +149,16 @@ class MyBot(commands.Bot): except Exception as e: kuby_logger.error(f"❌ Erreur lors de la synchronisation des commandes slash : {e}", exc_info=True) + async def close(self): + if hasattr(self, 'flask_process') and self.flask_process: + kuby_logger.info("Arrêt du serveur Flask interne...") + self.flask_process.terminate() + try: + self.flask_process.wait(timeout=5) + except subprocess.TimeoutExpired: + self.flask_process.kill() + await super().close() + # --- ÉVÉNEMENTS RESTAURÉS --- async def on_ready(self): diff --git a/requirements.txt b/requirements.txt index d4e9a44..fe0a75a 100755 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ discord.py>=2.3.0 python-dotenv>=1.0.0 Pillow>=10.0.0 aiohttp>=3.8.0 +flask>=3.0.0