Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
93
commandes/virement_ursaff.py
Normal file
93
commandes/virement_ursaff.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
class VirementUrssaf(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_ursaff", description="Fait un virement vers le compte indépendant URSAFF.")
|
||||
@app_commands.choices(banque=banque_choices)
|
||||
@app_commands.describe(montant="Montant à transférer", banque="Banque à utiliser")
|
||||
async def virement_ursaff(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
|
||||
|
||||
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 = {}
|
||||
|
||||
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 URSAFF si nécessaire
|
||||
if "ursaff" not in entreprises:
|
||||
entreprises["ursaff"] = {}
|
||||
if "URSAFF" not in entreprises["ursaff"]:
|
||||
entreprises["ursaff"]["URSAFF"] = {
|
||||
"rib": "00000 00000 00000000000 02",
|
||||
"solde": 0.0,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
|
||||
# Mise à jour des soldes
|
||||
compte["solde"] -= montant
|
||||
entreprises["ursaff"]["URSAFF"]["solde"] += montant
|
||||
|
||||
# Historique utilisateur
|
||||
compte["transactions"].append({
|
||||
"date": now,
|
||||
"type": "Virement",
|
||||
"source": "Vers URSAFF",
|
||||
"montant": -montant
|
||||
})
|
||||
|
||||
# Historique URSAFF
|
||||
entreprises["ursaff"]["URSAFF"]["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 compte **URSAFF** depuis **{banque_nom}**.",
|
||||
ephemeral=True
|
||||
)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(VirementUrssaf(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue