Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
92
commandes/ouvrir_comptes_entreprises.py
Normal file
92
commandes/ouvrir_comptes_entreprises.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import json
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
|
||||
COMPTES_ENTREPRISES_PATH = "comptes_entreprises.json"
|
||||
BANQUIER_ROLE_ID = 1360314740567576616 # ID du rôle des banquiers # ID du rôle banquier
|
||||
|
||||
def generer_rib():
|
||||
return " ".join(["".join(random.choices(string.digits, k=5)) for _ in range(4)])
|
||||
|
||||
def generer_mdp():
|
||||
return "".join(random.choices(string.ascii_letters + string.digits, k=8))
|
||||
|
||||
class OuvrirCompteEntreprise(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
banque_choix = [
|
||||
app_commands.Choice(name="Victoria's Credit Bank", value="Victoria's Credit Bank"),
|
||||
app_commands.Choice(name="NGC Bank", value="NGC Bank"),
|
||||
]
|
||||
|
||||
tva_choix = [
|
||||
app_commands.Choice(name="2%", value=2),
|
||||
app_commands.Choice(name="5%", value=5),
|
||||
app_commands.Choice(name="10%", value=10),
|
||||
app_commands.Choice(name="20%", value=20),
|
||||
]
|
||||
|
||||
@app_commands.command(name="ouvrir_compte_entreprise", description="Ouvre un compte bancaire pour une entreprise")
|
||||
@app_commands.choices(banque=banque_choix, tva=tva_choix)
|
||||
async def ouvrir_compte_entreprise(self, interaction: discord.Interaction, entreprise: str, banque: app_commands.Choice[str], tva: app_commands.Choice[int]):
|
||||
# ✅ Vérifie que l'utilisateur est banquier
|
||||
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 d'exécuter cette commande.", ephemeral=True)
|
||||
return
|
||||
|
||||
banque_name = banque.value
|
||||
entreprise = entreprise.strip()
|
||||
|
||||
# ✅ Chargement sécurisé du fichier
|
||||
if os.path.exists(COMPTES_ENTREPRISES_PATH):
|
||||
try:
|
||||
with open(COMPTES_ENTREPRISES_PATH, "r", encoding="utf-8") as f:
|
||||
comptes = json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
comptes = {}
|
||||
else:
|
||||
comptes = {}
|
||||
|
||||
if banque_name not in comptes:
|
||||
comptes[banque_name] = {}
|
||||
|
||||
if entreprise in comptes[banque_name]:
|
||||
await interaction.response.send_message(f"❌ Un compte existe déjà pour l'entreprise **{entreprise}** dans la banque **{banque_name}**.", ephemeral=True)
|
||||
return
|
||||
|
||||
rib = generer_rib()
|
||||
mdp = generer_mdp()
|
||||
|
||||
comptes[banque_name][entreprise] = {
|
||||
"rib": rib,
|
||||
"solde": 0,
|
||||
"mdp": mdp,
|
||||
"tva": tva.value,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
with open(COMPTES_ENTREPRISES_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(comptes, f, ensure_ascii=False, indent=4)
|
||||
|
||||
# ✅ MP à l'utilisateur avec le RIB et le mot de passe
|
||||
try:
|
||||
await interaction.user.send(
|
||||
f"🏦 Compte de l'entreprise **{entreprise}** ouvert avec succès dans la banque **{banque_name}** !\n"
|
||||
f"💳 RIB : `{rib}`\n"
|
||||
f"🔐 Mot de passe : `{mdp}`\n"
|
||||
f"💼 Taux de TVA : `{tva.value}%`\n\n"
|
||||
f"Conservez bien ces informations."
|
||||
)
|
||||
except discord.Forbidden:
|
||||
await interaction.response.send_message("⚠️ Impossible de vous envoyer un message privé avec les informations du compte.", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(f"✅ Le compte de l'entreprise **{entreprise}** a été créé avec succès.", ephemeral=True)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(OuvrirCompteEntreprise(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue