Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
122
commandes/virement_banquier_entreprise.py
Normal file
122
commandes/virement_banquier_entreprise.py
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
BANQUIER_ROLE_ID = 1360314740567576616 # ID du rôle des banquiers # ID du rôle banquier # ID du rôle des banquiers
|
||||
|
||||
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 any(role.id == BANQUIER_ROLE_ID for role in interaction.user.roles):
|
||||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue