Vicy_Publique/commandes/comptes_entreprises.py
2026-08-16 19:37:15 +02:00

73 lines
2.7 KiB
Python

import discord
from discord import app_commands
from discord.ext import commands
import json
class CompteEntreprise(commands.Cog):
def __init__(self, bot):
self.bot = bot
banque_choices = [
app_commands.Choice(name="Victoria's Credit Bank", value="Victoria's Credit Bank"),
app_commands.Choice(name="NGC Bank", value="NGC Bank"),
]
@app_commands.command(name="compte_entreprise", description="Consulte le solde et les transactions d'une entreprise.")
@app_commands.choices(banque=banque_choices)
async def compte_entreprise(
self,
interaction: discord.Interaction,
banque: app_commands.Choice[str],
nom_entreprise: str,
mot_de_passe: str
):
banque_nom = banque.value
try:
with open("comptes_entreprises.json", "r", encoding="utf-8") as f:
comptes = json.load(f)
except Exception:
await interaction.response.send_message("❌ Erreur de lecture des données bancaires.", ephemeral=True)
return
if banque_nom not in comptes or nom_entreprise not in comptes[banque_nom]:
await interaction.response.send_message("❌ Ce compte entreprise n'existe pas.", ephemeral=True)
return
compte = comptes[banque_nom][nom_entreprise]
# 🔐 Vérification du mot de passe avec la bonne clé
mdp_stocke = compte.get("mdp", "").strip()
mdp_fournit = mot_de_passe.strip()
if mdp_stocke != mdp_fournit:
await interaction.response.send_message("❌ Mot de passe incorrect.", ephemeral=True)
return
solde = compte.get("solde", 0)
transactions = compte.get("transactions", [])
embed = discord.Embed(
title=f"🏢 Compte Entreprise : {nom_entreprise}",
color=discord.Color.teal()
)
embed.add_field(name="🏦 Banque", value=banque_nom, inline=True)
embed.add_field(name="💰 Solde", value=f"{solde:.2f}€", inline=False)
if transactions:
last_transactions = transactions[-3:]
for tx in reversed(last_transactions):
desc = (
f"**Date**: {tx.get('date', 'N/A')}\n"
f"**Type**: {tx.get('type', 'N/A')}\n"
f"**Montant**: {tx.get('montant', 0)}€\n"
f"**Source**: {tx.get('source', 'N/A')}"
)
embed.add_field(name="📄 Transaction", value=desc, inline=False)
else:
embed.add_field(name="📄 Transactions", value="Aucune transaction récente.", inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)
async def setup(bot):
await bot.add_cog(CompteEntreprise(bot))