Vicy_Publique/commandes/compte.py

63 lines
2.3 KiB
Python
Raw Normal View History

2026-08-16 19:37:15 +02:00
import discord
from discord import app_commands
from discord.ext import commands
from utils.bank_manager import BankManager
bank_manager = BankManager()
2026-08-16 19:37:15 +02:00
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)
2026-08-16 19:37:15 +02:00
if not comptes:
await interaction.response.send_message(
"❌ Vous n'avez aucun compte bancaire. Utilisez `/mes-ribs` pour voir vos RIBs.",
ephemeral=True,
)
return
2026-08-16 19:37:15 +02:00
embed = discord.Embed(
title=f"💳 Comptes de {interaction.user.display_name}",
color=discord.Color.blue(),
2026-08-16 19:37:15 +02:00
)
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}€`")
2026-08-16 19:37:15 +02:00
else:
tx_lines.append(f"- {direction} **{tx_type}** : `{signe}{tx['montant']:.2f}€` vers `{other_rib or '?'}`")
2026-08-16 19:37:15 +02:00
tx_text = "\n".join(tx_lines) if tx_lines else "*Aucune transaction récente.*"
2026-08-16 19:37:15 +02:00
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,
2026-08-16 19:37:15 +02:00
)
await interaction.response.send_message(embed=embed, ephemeral=True)
2026-08-16 19:37:15 +02:00
async def setup(bot):
await bot.add_cog(Compte(bot))