Vicy_Publique/commandes/gouv.py
utilisateurqu c9ad155bf6 V2.0: Refonte système bancaire - DB SQLite, RIB FR, TVA auto, multi-banques
- Remplace JSON par SQLite (aiosqlite) pour atomicité et intégrité
- Nouveau format RIB français avec checksum modulo 97
- Chaque banque a son propre rôle Discord (isolation par serveur)
- TVA automatique Particulier -> Entreprise, redirection au Fisc
- Institutions gouvernementales avec droit d'audit optionnel
- Commandes: /gouv, /banque, /audit, /mes-ribs
- Supprime: 16 anciens fichiers (entreprises, FBM, URSAFF, etc.)
- Reset complet des données, repart de zéro
2026-08-18 17:42:03 +02:00

194 lines
8.5 KiB
Python

import discord
from discord import app_commands
from discord.ext import commands
from utils.guild_config import has_role
from utils.bank_manager import BankManager
bank_manager = BankManager()
class Gouv(commands.Cog):
def __init__(self, bot):
self.bot = bot
gouv_group = app_commands.Group(name="gouv", description="Commandes gouvernementales")
def _check_gouv(self, interaction: discord.Interaction) -> bool:
return has_role(interaction.user, "gouvernement")
@gouv_group.command(name="creer-banque", description="Créer une nouvelle banque commerciale")
@app_commands.describe(
nom="Nom de la banque (ex: NGC Bank)",
role="Le rôle Discord des banquiers de cette banque"
)
async def creer_banque(self, interaction: discord.Interaction, nom: str, role: discord.Role):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
try:
result = await bank_manager.creer_banque(interaction.guild.id, nom, role.id)
embed = discord.Embed(
title="🏦 Banque créée",
description=(
f"**{nom}** a été créée avec succès.\n\n"
f"**Rôle banquiers :** {role.mention}\n"
f"**Code établissement :** `{result['establishment_code']}`\n"
f"**ID banque :** `{result['id']}`"
),
color=discord.Color.green(),
)
await interaction.response.send_message(embed=embed, ephemeral=True)
except Exception as e:
await interaction.response.send_message(f"❌ Erreur : {e}", ephemeral=True)
@gouv_group.command(name="creer-institution", description="Créer une institution (Fisc, URSAFF, etc.)")
@app_commands.describe(
nom="Nom de l'institution",
role="Le rôle Discord qui gère cette institution",
audit="Peut-elle consulter les comptes de toutes les banques ?"
)
async def creer_institution(
self,
interaction: discord.Interaction,
nom: str,
role: discord.Role,
audit: bool = False,
):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
try:
result = await bank_manager.creer_institution(
interaction.guild.id, nom, role.id, audit
)
embed = discord.Embed(
title="🏛️ Institution créée",
description=(
f"**{nom}** a été créée.\n\n"
f"**Rôle :** {role.mention}\n"
f"**Droit d'audit :** {'✅ Oui' if audit else '❌ Non'}\n"
f"**ID :** `{result['id']}`"
),
color=discord.Color.blue(),
)
await interaction.response.send_message(embed=embed, ephemeral=True)
except Exception as e:
await interaction.response.send_message(f"❌ Erreur : {e}", ephemeral=True)
@gouv_group.command(name="config-fisc", description="Définir quelle institution reçoit la TVA")
@app_commands.describe(
institution="L'institution qui servira de Fisc"
)
async def config_fisc(self, interaction: discord.Interaction, institution: str):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
institutions = await bank_manager.lister_institutions(interaction.guild.id)
target = None
for inst in institutions:
if inst["name"].lower() == institution.lower():
target = inst
break
if not target:
await interaction.response.send_message(
f"❌ Institution **{institution}** introuvable. Institutions disponibles : {', '.join(i['name'] for i in institutions) or 'aucune'}",
ephemeral=True,
)
return
ok = await bank_manager.configurer_fisc(interaction.guild.id, target["id"])
if ok:
embed = discord.Embed(
title="🏛️ Fisc configuré",
description=f"**{target['name']}** reçoit désormais la TVA de tous les virements Particulier → Entreprise.",
color=discord.Color.green(),
)
await interaction.response.send_message(embed=embed, ephemeral=True)
else:
await interaction.response.send_message("❌ Erreur lors de la configuration.", ephemeral=True)
@gouv_group.command(name="lister-banques", description="Lister toutes les banques du serveur")
async def lister_banques(self, interaction: discord.Interaction):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
banques = await bank_manager.lister_banques(interaction.guild.id)
if not banques:
await interaction.response.send_message("Aucune banque configurée.", ephemeral=True)
return
embed = discord.Embed(title="🏦 Banques du serveur", color=discord.Color.blue())
for b in banques:
role = interaction.guild.get_role(b["role_id"])
role_text = role.mention if role else f"`{b['role_id']}` introuvable"
embed.add_field(
name=b["name"],
value=(
f"**Rôle :** {role_text}\n"
f"**Code établissement :** `{b['establishment_code']}`\n"
f"**Réserve :** `{b['vault_balance']:.2f}€`\n"
f"**Encours clients :** `{b['clients_total_balance']:.2f}€`"
),
inline=False,
)
await interaction.response.send_message(embed=embed, ephemeral=True)
@gouv_group.command(name="lister-institutions", description="Lister toutes les institutions du serveur")
async def lister_institutions(self, interaction: discord.Interaction):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
institutions = await bank_manager.lister_institutions(interaction.guild.id)
if not institutions:
await interaction.response.send_message("Aucune institution configurée.", ephemeral=True)
return
fisc_config = await bank_manager.get_fisc_config(interaction.guild.id)
fisc_id = fisc_config["institution_id"] if fisc_config else None
embed = discord.Embed(title="🏛️ Institutions du serveur", color=discord.Color.blue())
for inst in institutions:
role = interaction.guild.get_role(inst["role_id"]) if inst["role_id"] else None
role_text = role.mention if role else "Non assigné"
is_fisc = " 💰 **(Fisc)**" if inst["id"] == fisc_id else ""
embed.add_field(
name=f"{inst['name']}{is_fisc}",
value=(
f"**Rôle :** {role_text}\n"
f"**Audit :** {'✅ Toutes les banques' if inst['can_audit_all'] else '❌ Non'}\n"
f"**ID :** `{inst['id']}`"
),
inline=False,
)
await interaction.response.send_message(embed=embed, ephemeral=True)
@gouv_group.command(name="supprimer-banque", description="Supprimer une banque")
@app_commands.describe(nom="Nom de la banque à supprimer")
async def supprimer_banque(self, interaction: discord.Interaction, nom: str):
if not self._check_gouv(interaction):
await interaction.response.send_message("❌ Réservé au rôle **Gouvernement**.", ephemeral=True)
return
banque = await bank_manager.get_banque_by_name(interaction.guild.id, nom)
if not banque:
await interaction.response.send_message(f"❌ Banque **{nom}** introuvable.", ephemeral=True)
return
ok = await bank_manager.supprimer_banque(interaction.guild.id, banque["id"])
if ok:
await interaction.response.send_message(
f"✅ Banque **{nom}** supprimée avec tous ses comptes.", ephemeral=True
)
else:
await interaction.response.send_message("❌ Erreur lors de la suppression.", ephemeral=True)
async def setup(bot):
await bot.add_cog(Gouv(bot))