import discord from discord import app_commands from discord.ext import commands from utils.bank_manager import BankManager bank_manager = BankManager() class Compte(commands.Cog): def __init__(self, bot): self.bot = bot @app_commands.command(name="compte", description="Afficher vos comptes bancaires et vos dernières transactions") async def compte(self, interaction: discord.Interaction): comptes = await bank_manager.get_comptes_user(interaction.guild.id, interaction.user.id) if not comptes: await interaction.response.send_message( "❌ Vous n'avez aucun compte bancaire. Utilisez `/mes-ribs` pour voir vos RIBs.", ephemeral=True, ) return embed = discord.Embed( title=f"💳 Comptes de {interaction.user.display_name}", color=discord.Color.blue(), ) for c in comptes: transactions = await bank_manager.get_transactions(interaction.guild.id, c["rib"], limit=5) tva_text = f" | TVA: {c['tva_rate']}%" if c["account_type"] == "entreprise" else "" tx_lines = [] for tx in transactions: is_outgoing = tx["emetteur_rib"] == c["rib"] direction = "→" if is_outgoing else "←" other_rib = tx["destinataire_rib"] if is_outgoing else tx["emetteur_rib"] signe = "-" if is_outgoing else "+" tx_type = tx["type"] if tx_type == "tva_prelevee": tx_lines.append(f"- {direction} **TVA** : `{signe}{tx['montant']:.2f}€`") else: tx_lines.append(f"- {direction} **{tx_type}** : `{signe}{tx['montant']:.2f}€` vers `{other_rib or '?'}`") tx_text = "\n".join(tx_lines) if tx_lines else "*Aucune transaction récente.*" embed.add_field( name=f"🏦 {c['bank_name']} ({c['account_type']}){tva_text}", value=( f"**RIB :** `{c['rib']}`\n" f"**Solde :** `{c['solde']:.2f}€`\n\n" f"**Transactions récentes :**\n{tx_text}" ), inline=False, ) await interaction.response.send_message(embed=embed, ephemeral=True) async def setup(bot): await bot.add_cog(Compte(bot))