73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
|
|
import discord
|
||
|
|
from discord import app_commands
|
||
|
|
from discord.ext import commands
|
||
|
|
from utils.data_manager import DataManager
|
||
|
|
from datetime import datetime, timedelta
|
||
|
|
|
||
|
|
ADMIN_ROLE_ID = 1278305482926194701 # ID du rôle gouvernement # ID du rôle gouvernement
|
||
|
|
|
||
|
|
data_manager = DataManager()
|
||
|
|
|
||
|
|
class CreerIdentite(commands.Cog):
|
||
|
|
def __init__(self, bot):
|
||
|
|
self.bot = bot
|
||
|
|
|
||
|
|
@app_commands.command(name="creer_carte_identite", description="Créer une carte d'identité (Réservé aux admins)")
|
||
|
|
@app_commands.choices(sexe=[
|
||
|
|
app_commands.Choice(name="Homme", value="Homme"),
|
||
|
|
app_commands.Choice(name="Femme", value="Femme"),
|
||
|
|
app_commands.Choice(name="Autre", value="Autre")
|
||
|
|
])
|
||
|
|
async def creer_carte_identite(
|
||
|
|
self,
|
||
|
|
interaction: discord.Interaction,
|
||
|
|
utilisateur: discord.Member,
|
||
|
|
nom: str,
|
||
|
|
prenom: str,
|
||
|
|
date_naissance: str,
|
||
|
|
lieu_naissance: str,
|
||
|
|
sexe: app_commands.Choice[str]
|
||
|
|
):
|
||
|
|
"""Commande réservée aux admins pour créer une carte d'identité"""
|
||
|
|
|
||
|
|
if not any(role.id == ADMIN_ROLE_ID for role in interaction.user.roles):
|
||
|
|
await interaction.response.send_message(
|
||
|
|
"❌ Vous n'avez pas la permission de créer des cartes d'identité.",
|
||
|
|
ephemeral=True
|
||
|
|
)
|
||
|
|
return
|
||
|
|
|
||
|
|
user_id = str(utilisateur.id)
|
||
|
|
|
||
|
|
# ➡️ Plus de refus : on écrase directement l'ancienne carte
|
||
|
|
ancienne_carte = user_id in data_manager.identities
|
||
|
|
|
||
|
|
# 📅 Dates de création et d'expiration
|
||
|
|
date_creation = datetime.now()
|
||
|
|
date_expiration = (date_creation + timedelta(days=730)).strftime("%d/%m/%Y")
|
||
|
|
|
||
|
|
# 📦 Données à enregistrer
|
||
|
|
identity_data = {
|
||
|
|
"nom": nom.upper(),
|
||
|
|
"prenom": prenom.capitalize(),
|
||
|
|
"date_naissance": date_naissance,
|
||
|
|
"lieu_naissance": lieu_naissance,
|
||
|
|
"sexe": sexe.value,
|
||
|
|
"date_expiration": date_expiration
|
||
|
|
}
|
||
|
|
|
||
|
|
# 💾 Enregistrement
|
||
|
|
data_manager.identities[user_id] = identity_data
|
||
|
|
data_manager.save_data()
|
||
|
|
|
||
|
|
# 📢 Message différent selon si c'était une ancienne carte ou non
|
||
|
|
if ancienne_carte:
|
||
|
|
message = f"✅ Carte d'identité de {utilisateur.mention} **mise à jour** avec succès !"
|
||
|
|
else:
|
||
|
|
message = f"✅ Carte d'identité créée pour {utilisateur.mention} avec succès !"
|
||
|
|
|
||
|
|
await interaction.response.send_message(message, ephemeral=False)
|
||
|
|
|
||
|
|
async def setup(bot):
|
||
|
|
await bot.add_cog(CreerIdentite(bot))
|