Amélioration modules updater et sélection des IA suivant disponibilités
Build and Push Docker Image / build-and-push (push) Successful in 7m31s

This commit is contained in:
xavier committed 2026-09-05 06:52:42 +02:00
1 parent d36cb07ab1
commit 7cd6e1db6e
1 file changed
+17 -8
+17 -8
View File
@@ -211,26 +211,35 @@ def obtenir_solde(utilisateur_nom: str) -> float:
# --- SYNCHRONISATION DIRECTE POUR L'ADMINISTRATEUR PRINCIPAL ---
if utilisateur_nom.lower() in ["xavier"]:
api_key = os.getenv("OPENROUTER_API_KEY")
if api_key:
if not api_key:
log_event("CRITICAL", "BILLING", "Clé OPENROUTER_API_KEY introuvable dans l'environnement ! La synchronisation est impossible.")
else:
try:
resp = requests.get("https://openrouter.ai/api/v1/auth/key", headers={"Authorization": f"Bearer {api_key}"}, timeout=3)
resp = requests.get("https://openrouter.ai/api/v1/auth/key", headers={"Authorization": f"Bearer {api_key}"}, timeout=5)
if resp.status_code == 200:
data = resp.json().get("data", {})
credit_total = data.get('usage', 0.0)
limite_restante = data.get('limit_remaining')
balance = data.get('balance', 0.0)
usage = float(data.get('usage', 0.0))
limit = data.get('limit')
balance = data.get('balance')
vrai_solde = float(limite_restante) if limite_restante is not None else float(balance)
vrai_solde = 0.0
if limit is not None:
vrai_solde = float(limit) - usage
elif balance is not None:
vrai_solde = float(balance)
if vrai_solde > 0 or limite_restante is not None:
if vrai_solde > 0 or (limit is not None) or (balance is not None):
soldes = charger_soldes()
soldes["cagnotte_commune_vip"] = vrai_solde
soldes["xavier"] = vrai_solde
sauvegarder_soldes(soldes)
return vrai_solde
else:
log_event("ERROR", "BILLING", f"Refus de l'API OpenRouter (Code {resp.status_code}) : {resp.text}")
except Exception as e:
log_event("WARNING", "BILLING", f"Échec de synchronisation OpenRouter : {e}")
log_event("WARNING", "BILLING", f"Échec réseau lors de la connexion à OpenRouter : {e}")
# --- COMPORTEMENT STANDARD POUR LES AUTRES UTILISATEURS ---
soldes = charger_soldes()