76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
|
|
import discord
|
||
|
|
from discord import app_commands
|
||
|
|
from discord.ext import commands
|
||
|
|
|
||
|
|
from utils.guild_config import has_role, get_guild_role
|
||
|
|
from utils.bank_manager import BankManager
|
||
|
|
|
||
|
|
bank_manager = BankManager()
|
||
|
|
|
||
|
|
|
||
|
|
class Audit(commands.Cog):
|
||
|
|
def __init__(self, bot):
|
||
|
|
self.bot = bot
|
||
|
|
|
||
|
|
audit_group = app_commands.Group(name="audit", description="Audit bancaire (institutions)")
|
||
|
|
|
||
|
|
@audit_group.command(name="consulter-banque", description="Consulter les comptes d'une banque (institutions avec audit)")
|
||
|
|
@app_commands.describe(nom_banque="Nom de la banque à auditer")
|
||
|
|
async def consulter_banque(self, interaction: discord.Interaction, nom_banque: str):
|
||
|
|
user_roles = [r.id for r in interaction.user.roles]
|
||
|
|
institutions = await bank_manager.lister_institutions(interaction.guild.id)
|
||
|
|
|
||
|
|
authorized = None
|
||
|
|
for inst in institutions:
|
||
|
|
if inst["role_id"] and inst["role_id"] in user_roles and inst["can_audit_all"]:
|
||
|
|
authorized = inst
|
||
|
|
break
|
||
|
|
|
||
|
|
if not authorized:
|
||
|
|
await interaction.response.send_message(
|
||
|
|
"❌ Vous n'avez pas le droit d'audit. Réservé aux institutions avec le droit d'audit activé.",
|
||
|
|
ephemeral=True,
|
||
|
|
)
|
||
|
|
return
|
||
|
|
|
||
|
|
banque = await bank_manager.get_banque_by_name(interaction.guild.id, nom_banque)
|
||
|
|
if not banque:
|
||
|
|
banques = await bank_manager.lister_banques(interaction.guild.id)
|
||
|
|
noms = ", ".join(b["name"] for b in banques) or "aucune"
|
||
|
|
await interaction.response.send_message(
|
||
|
|
f"❌ Banque **{nom_banque}** introuvable. Banques disponibles : {noms}",
|
||
|
|
ephemeral=True,
|
||
|
|
)
|
||
|
|
return
|
||
|
|
|
||
|
|
comptes = await bank_manager.get_comptes_banque(interaction.guild.id, banque["id"])
|
||
|
|
if not comptes:
|
||
|
|
await interaction.response.send_message("Aucun compte dans cette banque.", ephemeral=True)
|
||
|
|
return
|
||
|
|
|
||
|
|
embed = discord.Embed(
|
||
|
|
title=f"🔍 Audit : {banque['name']}",
|
||
|
|
description=f"Effectué par l'institution **{authorized['name']}**",
|
||
|
|
color=discord.Color.orange(),
|
||
|
|
)
|
||
|
|
|
||
|
|
for c in comptes:
|
||
|
|
member = interaction.guild.get_member(c["user_id"])
|
||
|
|
name = member.display_name if member else f"User#{c['user_id']}"
|
||
|
|
tva_text = f" | TVA: {c['tva_rate']}%" if c["account_type"] == "entreprise" else ""
|
||
|
|
embed.add_field(
|
||
|
|
name=f"{name} ({c['account_type']})",
|
||
|
|
value=(
|
||
|
|
f"**RIB :** `{c['rib']}`\n"
|
||
|
|
f"**Solde :** `{c['solde']:.2f}€`{tva_text}"
|
||
|
|
),
|
||
|
|
inline=False,
|
||
|
|
)
|
||
|
|
|
||
|
|
embed.set_footer(text=f"Total : {len(comptes)} compte(s) | Réserve banque : {banque['vault_balance']:.2f}€")
|
||
|
|
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||
|
|
|
||
|
|
|
||
|
|
async def setup(bot):
|
||
|
|
await bot.add_cog(Audit(bot))
|