Vicy_Publique/commandes/identite.py

72 lines
2.5 KiB
Python
Raw Normal View History

2026-08-16 19:37:15 +02:00
import discord
from discord import app_commands
from discord.ext import commands
from utils.data_manager import DataManager
from datetime import datetime, timedelta
from utils.guild_config import has_role
2026-08-16 19:37:15 +02:00
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 has_role(interaction.user, "gouvernement"):
2026-08-16 19:37:15 +02:00
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))