2026-08-16 19:37:15 +02:00
import json
import discord
from discord import app_commands
from discord . ext import commands
from datetime import datetime
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
from utils . guild_config import has_role
2026-08-16 19:37:15 +02:00
class VirementBanquier ( 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 = " virement_banquier " , description = " Effectue un virement au nom d ' un client (réservé aux banquiers). " )
@app_commands.choices ( banque = banque_choices )
async def virement_banquier (
self ,
interaction : discord . Interaction ,
rib_emetteur : str ,
montant : float ,
rib_destinataire : str ,
banque : app_commands . Choice [ str ]
) :
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
if not has_role ( interaction . user , " banquier " ) :
2026-08-16 19:37:15 +02:00
await interaction . response . send_message ( " ❌ Vous n ' avez pas la permission d ' utiliser cette commande. " , ephemeral = True )
return
banque_nom = banque . value
try :
with open ( " comptes_bancaires.json " , " r " , encoding = " utf-8 " ) as f :
comptes = json . load ( f )
except :
await interaction . response . send_message ( " ❌ Erreur de lecture des comptes bancaires. " , ephemeral = True )
return
# Trouver les ID à partir des RIB
emetteur_id = None
destinataire_id = None
for user_id , data in comptes . get ( banque_nom , { } ) . items ( ) :
if data . get ( " rib " ) == rib_emetteur :
emetteur_id = user_id
if data . get ( " rib " ) == rib_destinataire :
destinataire_id = user_id
if not emetteur_id :
await interaction . response . send_message ( " ❌ Le RIB émetteur est introuvable dans cette banque. " , ephemeral = True )
return
if not destinataire_id :
await interaction . response . send_message ( " ❌ Le RIB destinataire est introuvable dans cette banque. " , ephemeral = True )
return
# Vérifier le solde
if comptes [ banque_nom ] [ emetteur_id ] [ " solde " ] < montant :
await interaction . response . send_message ( " ❌ Le solde du compte émetteur est insuffisant. " , ephemeral = True )
return
# Exécuter le virement
comptes [ banque_nom ] [ emetteur_id ] [ " solde " ] - = montant
comptes [ banque_nom ] [ emetteur_id ] [ " transactions " ] . append ( {
" date " : datetime . now ( ) . strftime ( " %d / % m/ % Y % H: % M: % S " ) ,
" type " : " Virement manuel (par banquier) " ,
" source " : f " Vers RIB { rib_destinataire } " ,
" montant " : - montant
} )
comptes [ banque_nom ] [ destinataire_id ] [ " solde " ] + = montant
comptes [ banque_nom ] [ destinataire_id ] [ " transactions " ] . append ( {
" date " : datetime . now ( ) . strftime ( " %d / % m/ % Y % H: % M: % S " ) ,
" type " : " Virement reçu (par banquier) " ,
" source " : f " RIB { rib_emetteur } " ,
" montant " : montant
} )
with open ( " comptes_bancaires.json " , " w " , encoding = " utf-8 " ) as f :
json . dump ( comptes , f , ensure_ascii = False , indent = 4 )
await interaction . response . send_message ( f " ✅ Virement de ** { montant : .2f } €** effectué de ** { rib_emetteur } ** vers ** { rib_destinataire } ** dans ** { banque_nom } **. " , ephemeral = True )
async def setup ( bot ) :
await bot . add_cog ( VirementBanquier ( bot ) )