97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
import discord
|
|
from discord import app_commands
|
|
from discord.ext import commands
|
|
import json
|
|
from datetime import datetime
|
|
|
|
class VirementFBM(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_fbm", description="Fait un virement au compte indépendant FBM.")
|
|
@app_commands.choices(banque=banque_choices)
|
|
@app_commands.describe(montant="Montant à transférer", banque="Banque à utiliser")
|
|
async def virement_fbm(self, interaction: discord.Interaction, montant: float, banque: app_commands.Choice[str]):
|
|
auteur_id = str(interaction.user.id)
|
|
banque_nom = banque.value
|
|
|
|
if montant <= 0:
|
|
await interaction.response.send_message("❌ Le montant doit être supérieur à 0.", ephemeral=True)
|
|
return
|
|
|
|
# Charger les fichiers
|
|
try:
|
|
with open("comptes_bancaires.json", "r", encoding="utf-8") as f:
|
|
comptes = json.load(f)
|
|
except Exception:
|
|
await interaction.response.send_message("❌ Erreur lors de la lecture des comptes bancaires.", ephemeral=True)
|
|
return
|
|
|
|
try:
|
|
with open("comptes_entreprises.json", "r", encoding="utf-8") as f:
|
|
entreprises = json.load(f)
|
|
except:
|
|
entreprises = {}
|
|
|
|
# Vérification du compte de l'utilisateur
|
|
if banque_nom not in comptes or auteur_id not in comptes[banque_nom]:
|
|
await interaction.response.send_message("❌ Tu n'as pas de compte dans cette banque.", ephemeral=True)
|
|
return
|
|
|
|
compte = comptes[banque_nom][auteur_id]
|
|
if compte["solde"] < montant:
|
|
await interaction.response.send_message("❌ Solde insuffisant pour effectuer le virement.", ephemeral=True)
|
|
return
|
|
|
|
# Initialiser FBM si nécessaire
|
|
if "fbm" not in entreprises:
|
|
entreprises["fbm"] = {}
|
|
if "FBM" not in entreprises["fbm"]:
|
|
entreprises["fbm"]["FBM"] = {
|
|
"rib": "00000 00000 00000000000 03",
|
|
"solde": 0.0,
|
|
"transactions": []
|
|
}
|
|
|
|
now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
|
|
# Mise à jour des soldes
|
|
compte["solde"] -= montant
|
|
entreprises["fbm"]["FBM"]["solde"] += montant
|
|
|
|
# Historique utilisateur
|
|
compte["transactions"].append({
|
|
"date": now,
|
|
"type": "Virement",
|
|
"source": f"Vers FBM",
|
|
"montant": -montant
|
|
})
|
|
|
|
# Historique FBM
|
|
entreprises["fbm"]["FBM"]["transactions"].append({
|
|
"date": now,
|
|
"type": "Virement reçu",
|
|
"source": interaction.user.name,
|
|
"montant": montant
|
|
})
|
|
|
|
# Sauvegarde
|
|
with open("comptes_bancaires.json", "w", encoding="utf-8") as f:
|
|
json.dump(comptes, f, indent=4, ensure_ascii=False)
|
|
|
|
with open("comptes_entreprises.json", "w", encoding="utf-8") as f:
|
|
json.dump(entreprises, f, indent=4, ensure_ascii=False)
|
|
|
|
# Confirmation
|
|
await interaction.response.send_message(
|
|
f"✅ Virement de **{montant:.2f}€** envoyé au compte **FBM** depuis **{banque_nom}**.",
|
|
ephemeral=True
|
|
)
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(VirementFBM(bot))
|