diff --git a/bot.py b/bot.py index eca411f..eb88dde 100755 --- a/bot.py +++ b/bot.py @@ -1,4 +1,8 @@ import os +# Nettoyer les variables de certificats SSL corrompues ou obsolètes pour éviter les crashs TLS +os.environ.pop("REQUESTS_CA_BUNDLE", None) +os.environ.pop("SSL_CERT_FILE", None) + import sys from dotenv import load_dotenv diff --git a/commandes/bug_report.py b/commandes/bug_report.py index 392e09d..956bac4 100644 --- a/commandes/bug_report.py +++ b/commandes/bug_report.py @@ -178,17 +178,22 @@ class BugReport(commands.Cog): self.bot = bot async def cog_load(self): - # ❌ DÉSACTIVÉ : Le webhook est géré par serveur_flask.py (port 5000) - # Le serveur Flask proxyfie déjà les webhooks GitLab vers ce cog via /bot_event - kuby_logger.info("BugReport cog chargé (webhook géré par serveur_flask.py)") - # Créer le dossier pour REPORTS_FILE s'il n'existe pas + kuby_logger.info("BugReport cog chargé. Démarrage du serveur de relais interne (port 5001)...") REPORTS_DIR = os.path.dirname(REPORTS_FILE) os.makedirs(REPORTS_DIR, exist_ok=True) + await self._start_webhook_server() async def _start_webhook_server(self): - # ❌ FONCTION DÉSACTIVÉE (voir cog_load) - kuby_logger.warning("Tentative d'appel à _start_webhook_server() - cette fonction est désactivée") - return + try: + app = web.Application() + app.router.add_post('/bot_event', self.handle_bot_event) + self.runner = web.AppRunner(app) + await self.runner.setup() + self.site = web.TCPSite(self.runner, '127.0.0.1', 5001) + await self.site.start() + kuby_logger.info("Internal Bot Webhook Server started on 127.0.0.1:5001") + except Exception as e: + kuby_logger.error(f"Failed to start Internal Bot Webhook Server: {e}") def cog_unload(self): if hasattr(self, 'runner'): diff --git a/serveur_flask.py b/serveur_flask.py index 470dc14..da4f577 100644 --- a/serveur_flask.py +++ b/serveur_flask.py @@ -1,11 +1,15 @@ import os, subprocess, threading, requests +# Nettoyer les variables de certificats SSL corrompues ou obsolètes pour éviter les crashs TLS +os.environ.pop("REQUESTS_CA_BUNDLE", None) +os.environ.pop("SSL_CERT_FILE", None) + from flask import Flask, request, abort from datetime import datetime, timezone app = Flask(__name__) # --- CONFIGURATION --- -PROJECT_PATH = "/home/discord/Bot/Kuby_V2" +PROJECT_PATH = "/home/discord/Bot/Kuby" WEBHOOK_SECRET = "Nois2" PROCESS_NAME = "kuby" DISCORD_LOG_URL = "https://discord.com/api/webhooks/1482148910888652910/IA9CcOWtjGswbuxMaOu_6uaclv5zojZo4ttxtV6RYyZzJ9gW7BF7xp_Zv3oPIjYEuh8o" @@ -38,17 +42,32 @@ def run_mep_logic(author, commit_msg, branch="main"): send_discord_log("EN COURS", f"Déploiement branch **{branch}** lancé sur la machine de guerre...", 3447003, author, commit_msg) try: - os.chdir(PROJECT_PATH) + target_path = PROJECT_PATH + use_rsync = False + if not os.path.exists(os.path.join(target_path, ".git")): + alt_path = "/home/discord/Bot/Kuby" + if os.path.exists(os.path.join(alt_path, ".git")): + print(f"[!] {target_path} n'est pas un dépôt Git. Utilisation du dépôt {alt_path} et rsync.") + target_path = alt_path + use_rsync = True + else: + raise RuntimeError(f"Aucun dépôt Git trouvé dans {target_path} ou {alt_path}") + + os.chdir(target_path) # 1. GIT subprocess.run(["git", "fetch", "origin"], check=True) subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], check=True) + # 2. RSYNC (si on utilise le fallback de dépôt) + if use_rsync: + subprocess.run(["rsync", "-a", "--exclude=.git", "--exclude=venv", "--exclude=.venv", "--exclude=__pycache__", f"{target_path}/", f"{PROJECT_PATH}/"], check=True) + duration = (datetime.now() - start_time).total_seconds() msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré." send_discord_log("VALIDÉ", msg, 3066993, author, commit_msg) - # 2. PM2 (Appelé après le message pour éviter que le kill du serv ne bloque l'envoi) + # 3. PM2 (Appelé après le message pour éviter que le kill du serv ne bloque l'envoi) subprocess.run(f"pm2 restart {PROCESS_NAME}", shell=True, check=True, capture_output=True) except Exception as e: