86 lines
No EOL
3.4 KiB
Python
86 lines
No EOL
3.4 KiB
Python
import discord
|
|
from discord import app_commands
|
|
from discord.ext import commands
|
|
import json
|
|
from datetime import datetime
|
|
|
|
class VirementGouvernement(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_gouvernement", description="Effectue un virement au Gouvernement.")
|
|
@app_commands.choices(banque=banque_choices)
|
|
@app_commands.describe(montant="Le montant à envoyer", banque="Banque à utiliser pour le virement")
|
|
async def virement_gouvernement(self, interaction: discord.Interaction, montant: float, banque: app_commands.Choice[str]):
|
|
auteur_id = str(interaction.user.id)
|
|
banque_source = banque.value
|
|
|
|
if montant <= 0:
|
|
await interaction.response.send_message("❌ Le montant doit être supérieur à zéro.", ephemeral=True)
|
|
return
|
|
|
|
# Charger les fichiers
|
|
try:
|
|
with open('comptes_bancaires.json', 'r', encoding='utf-8') as f:
|
|
comptes = json.load(f)
|
|
with open('comptes_entreprises.json', 'r', encoding='utf-8') as f:
|
|
entreprises = json.load(f)
|
|
except Exception as e:
|
|
await interaction.response.send_message(f"❌ Erreur de lecture des fichiers : {e}", ephemeral=True)
|
|
return
|
|
|
|
if banque_source not in comptes or auteur_id not in comptes[banque_source]:
|
|
await interaction.response.send_message(f"❌ Tu n'as pas de compte dans la banque **{banque_source}**.", ephemeral=True)
|
|
return
|
|
|
|
compte_user = comptes[banque_source][auteur_id]
|
|
if compte_user["solde"] < montant:
|
|
await interaction.response.send_message("❌ Solde insuffisant pour effectuer ce virement.", ephemeral=True)
|
|
return
|
|
|
|
# Vérifier ou créer le compte Gouvernement
|
|
if "Gouvernement" not in entreprises:
|
|
entreprises["Gouvernement"] = {}
|
|
if "GOUV" not in entreprises["Gouvernement"]:
|
|
entreprises["Gouvernement"]["GOUV"] = {
|
|
"rib": "00000 00000 00000000000 00",
|
|
"solde": 0.0,
|
|
"transactions": []
|
|
}
|
|
|
|
# Effectuer le virement
|
|
now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
compte_user["solde"] -= montant
|
|
entreprises["Gouvernement"]["GOUV"]["solde"] += montant
|
|
|
|
compte_user["transactions"].append({
|
|
"date": now,
|
|
"type": "Virement",
|
|
"source": f"Vers Gouvernement",
|
|
"montant": -montant
|
|
})
|
|
entreprises["Gouvernement"]["GOUV"]["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)
|
|
|
|
await interaction.response.send_message(
|
|
f"✅ Virement de **{montant:.2f}€** envoyé au Gouvernement avec succès.",
|
|
ephemeral=True
|
|
)
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(VirementGouvernement(bot)) |