Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
76
commandes/ouvrir_compte.py
Normal file
76
commandes/ouvrir_compte.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
from utils.banque_manager import BanqueManager
|
||||
import random
|
||||
|
||||
# Rôle nécessaire pour créer un compte
|
||||
BANQUIER_ROLE_ID = 1360314740567576616 # ID du rôle des banquiers # ID du rôle banquier
|
||||
|
||||
# Liste des banques disponibles (id interne : nom affiché)
|
||||
BANQUES = {
|
||||
"Victoria's Credit Bank": "Victoria's Credit Bank",
|
||||
"NGC Bank": "Nexus Global Corporation Bank"
|
||||
}
|
||||
|
||||
banque_manager = BanqueManager()
|
||||
|
||||
class OuvrirCompte(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@app_commands.command(name="ouvrir_compte", description="Ouvre un compte bancaire pour un utilisateur (banquier uniquement).")
|
||||
@app_commands.choices(
|
||||
banque=[app_commands.Choice(name=nom, value=id_banque) for id_banque, nom in BANQUES.items()]
|
||||
)
|
||||
async def ouvrir_compte(self, interaction: discord.Interaction, utilisateur: discord.Member, banque: app_commands.Choice[str]):
|
||||
banque_id = banque.value
|
||||
banque_nom = BANQUES[banque_id]
|
||||
|
||||
# Vérification du rôle de 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'ouvrir un compte.", ephemeral=True)
|
||||
return
|
||||
|
||||
user_id = str(utilisateur.id)
|
||||
banque_manager.load_data()
|
||||
|
||||
# Conversion automatique si l'ancien format est utilisé
|
||||
if all(isinstance(v, dict) and 'rib' in v for v in banque_manager.comptes.values()):
|
||||
banque_manager.comptes = {"vicynationale": banque_manager.comptes}
|
||||
|
||||
# Vérification si la banque existe dans les données
|
||||
if banque_id not in banque_manager.comptes:
|
||||
banque_manager.comptes[banque_id] = {}
|
||||
|
||||
# Vérification si l'utilisateur a déjà un compte dans cette banque
|
||||
if user_id in banque_manager.comptes[banque_id]:
|
||||
await interaction.response.send_message(
|
||||
f"❌ {utilisateur.mention} possède déjà un compte à la {banque_nom} !",
|
||||
ephemeral=True
|
||||
)
|
||||
return
|
||||
|
||||
# Génération du RIB aléatoire
|
||||
rib = f"{random.randint(10000, 99999)} {random.randint(10000, 99999)} {random.randint(10000000000, 99999999999)} {random.randint(10, 99)}"
|
||||
|
||||
# Création du compte
|
||||
banque_manager.comptes[banque_id][user_id] = {
|
||||
"rib": rib,
|
||||
"solde": 0.0,
|
||||
"transactions": []
|
||||
}
|
||||
|
||||
banque_manager.save_data()
|
||||
|
||||
# Envoi du RIB en MP à l'utilisateur cible
|
||||
try:
|
||||
await utilisateur.send(f"🏦 Un compte a été créé pour vous à la **{banque_nom}**.\nVoici votre RIB : `{rib}`")
|
||||
except discord.Forbidden:
|
||||
await interaction.response.send_message("❌ Impossible d'envoyer le RIB en message privé (l'utilisateur a les MP fermés).", ephemeral=True)
|
||||
return
|
||||
|
||||
await interaction.response.send_message(f"✅ Compte créé avec succès pour {utilisateur.mention} à la **{banque_nom}**.", ephemeral=True)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(OuvrirCompte(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue