- 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
121 lines
4.7 KiB
Python
121 lines
4.7 KiB
Python
import discord
|
|
from discord import app_commands
|
|
from discord.ext import commands
|
|
import json
|
|
from datetime import datetime
|
|
from utils.guild_config import has_role
|
|
|
|
class VirementBanquierEntreprise(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
banques = [
|
|
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_entreprise", description="Fait un virement depuis une entreprise avec mot de passe (réservé aux banquiers).")
|
|
@app_commands.choices(banque=banques)
|
|
async def virement_banquier_entreprise(
|
|
self,
|
|
interaction: discord.Interaction,
|
|
banque: app_commands.Choice[str],
|
|
nom_entreprise: str,
|
|
mot_de_passe: str,
|
|
rib_destinataire: str,
|
|
montant: float
|
|
):
|
|
if not has_role(interaction.user, "banquier"):
|
|
await interaction.response.send_message("❌ Vous n'avez pas la permission de faire cette commande.", ephemeral=True)
|
|
return
|
|
|
|
banque_nom = banque.value
|
|
|
|
# Chargement des fichiers
|
|
try:
|
|
with open("comptes_entreprises.json", "r", encoding="utf-8") as f:
|
|
entreprises = json.load(f)
|
|
with open("comptes_bancaires.json", "r", encoding="utf-8") as f:
|
|
particuliers = json.load(f)
|
|
except Exception:
|
|
await interaction.response.send_message("❌ Erreur de lecture des fichiers JSON.", ephemeral=True)
|
|
return
|
|
|
|
# Vérification de l'entreprise
|
|
if banque_nom not in entreprises or nom_entreprise not in entreprises[banque_nom]:
|
|
await interaction.response.send_message("❌ Compte entreprise introuvable.", ephemeral=True)
|
|
return
|
|
|
|
compte_entreprise = entreprises[banque_nom][nom_entreprise]
|
|
|
|
if compte_entreprise.get("mdp") != mot_de_passe:
|
|
await interaction.response.send_message("❌ Mot de passe incorrect.", ephemeral=True)
|
|
return
|
|
|
|
if compte_entreprise["solde"] < montant:
|
|
await interaction.response.send_message("❌ Solde insuffisant pour ce virement.", ephemeral=True)
|
|
return
|
|
|
|
# Recherche du compte destinataire (entreprise ou particulier)
|
|
destinataire_id = None
|
|
banque_destinataire = None
|
|
is_entreprise = False
|
|
|
|
# Recherche dans entreprises
|
|
for bq, entreprises_data in entreprises.items():
|
|
for nom, infos in entreprises_data.items():
|
|
if infos.get("rib") == rib_destinataire:
|
|
destinataire_id = nom
|
|
banque_destinataire = bq
|
|
is_entreprise = True
|
|
break
|
|
if destinataire_id:
|
|
break
|
|
|
|
# Sinon, recherche dans particuliers
|
|
if not destinataire_id:
|
|
for bq, clients in particuliers.items():
|
|
for user_id, infos in clients.items():
|
|
if infos.get("rib") == rib_destinataire:
|
|
destinataire_id = user_id
|
|
banque_destinataire = bq
|
|
is_entreprise = False
|
|
break
|
|
if destinataire_id:
|
|
break
|
|
|
|
if not destinataire_id:
|
|
await interaction.response.send_message("❌ RIB destinataire introuvable.", ephemeral=True)
|
|
return
|
|
|
|
# Retrait du montant
|
|
compte_entreprise["solde"] -= montant
|
|
compte_entreprise["transactions"].append({
|
|
"date": datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
|
|
"type": "Virement",
|
|
"source": f"Entreprise {nom_entreprise}",
|
|
"montant": -montant,
|
|
"destinataire": rib_destinataire
|
|
})
|
|
|
|
# Créditer le destinataire
|
|
compte_cible = entreprises if is_entreprise else particuliers
|
|
compte_data = compte_cible[banque_destinataire][destinataire_id]
|
|
compte_data["solde"] += montant
|
|
compte_data["transactions"].append({
|
|
"date": datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
|
|
"type": "Virement reçu",
|
|
"source": nom_entreprise,
|
|
"montant": montant
|
|
})
|
|
|
|
# Sauvegarde
|
|
with open("comptes_entreprises.json", "w", encoding="utf-8") as f:
|
|
json.dump(entreprises, f, ensure_ascii=False, indent=4)
|
|
with open("comptes_bancaires.json", "w", encoding="utf-8") as f:
|
|
json.dump(particuliers, f, ensure_ascii=False, indent=4)
|
|
|
|
await interaction.response.send_message(f"✅ Virement de **{montant:.2f}€** effectué depuis **{nom_entreprise}** vers **{rib_destinataire}**.")
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(VirementBanquierEntreprise(bot))
|