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 utils.card_generator import CardGenerator
|
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
|
|
|
from utils.guild_config import has_role
|
2026-08-16 19:37:15 +02:00
|
|
|
|
|
|
|
|
card_generator = CardGenerator()
|
|
|
|
|
|
|
|
|
|
class VoirIdentite(commands.Cog):
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
|
|
@app_commands.command(name="voir_carte_identite", description="Afficher votre carte d'identité ou celle d'un autre utilisateur")
|
|
|
|
|
async def voir_carte_identite(self, interaction: discord.Interaction, utilisateur: discord.Member = None):
|
|
|
|
|
"""Affiche la carte d'identité d'un utilisateur"""
|
|
|
|
|
|
|
|
|
|
target_user = utilisateur or interaction.user
|
|
|
|
|
|
Modularize bot: per-guild config system for roles/channels/categories
- Add utils/guild_config.py: centralized config loader per guild (data/guilds/{id}.json)
- Add commandes/config.py: /config set_role, /config set_channel, /config set_category, /config voir, /config reset
- Replace ALL hardcoded role IDs (banquier, gouvernement, citoyen, staff, ems, permis, fbm, ursaff, etc.) with guild_config lookups
- Replace ALL hardcoded channel IDs (welcome, candidature, questions, mp_reception) with guild_config lookups
- Replace ALL hardcoded category IDs (ticket) with guild_config lookups
- Remove duplicate commandes/welcome_message.py (kept utils/ version)
- Remove 20+ hardcoded snowflake IDs across 22 files
- Guilds configure via /config on Discord, no code changes needed
2026-08-17 00:12:57 +02:00
|
|
|
if utilisateur and utilisateur != interaction.user and not has_role(interaction.user, "gouvernement"):
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"🚫 Vous n'avez pas l'autorisation de voir la carte d'identité d'un autre utilisateur.",
|
|
|
|
|
ephemeral=True
|
|
|
|
|
)
|
|
|
|
|
return
|
2026-08-16 19:37:15 +02:00
|
|
|
|
|
|
|
|
user_id = str(target_user.id)
|
|
|
|
|
|
|
|
|
|
# 🧠 Recréer un DataManager à chaque commande
|
|
|
|
|
data_manager = DataManager()
|
|
|
|
|
|
|
|
|
|
# 🔎 Récupération des données
|
|
|
|
|
identity_data = data_manager.identities.get(user_id)
|
|
|
|
|
|
|
|
|
|
if identity_data is None:
|
|
|
|
|
await interaction.response.send_message(
|
|
|
|
|
"❌ Cet utilisateur ne possède pas de carte d'identité.",
|
|
|
|
|
ephemeral=True
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# 🛡️ Vérification que l'identité est complète
|
|
|
|
|
if "date_expiration" not in identity_data:
|
|
|
|
|
identity_data["date_expiration"] = "Non spécifiée"
|
|
|
|
|
|
|
|
|
|
# 🖼️ Génération de l'image de la carte
|
|
|
|
|
card_buffer = await card_generator.create_identity_card(target_user, identity_data)
|
|
|
|
|
|
|
|
|
|
# 📩 Envoi du fichier + embed
|
|
|
|
|
file = discord.File(card_buffer, filename="carte_identite.png")
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title=f"🪪 Carte d'identité de {target_user.display_name}",
|
|
|
|
|
color=0x2ecc71
|
|
|
|
|
)
|
|
|
|
|
embed.set_image(url="attachment://carte_identite.png")
|
|
|
|
|
|
|
|
|
|
await interaction.response.send_message(file=file, embed=embed, ephemeral=False)
|
|
|
|
|
|
|
|
|
|
async def setup(bot):
|
|
|
|
|
await bot.add_cog(VoirIdentite(bot))
|