Correction du bug "wl is not found"
This commit is contained in:
parent
dd24225120
commit
6372014c99
2 changed files with 158 additions and 17 deletions
104
commandes/convocation.py
Executable file
104
commandes/convocation.py
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
|
||||
class Convocation(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@app_commands.command(
|
||||
name="convocation",
|
||||
description="Convocation d’un membre"
|
||||
)
|
||||
@app_commands.describe(
|
||||
membre="Le membre à convoquer",
|
||||
raison="La raison de la convocation",
|
||||
heure="L’heure de la convocation"
|
||||
)
|
||||
@app_commands.checks.has_permissions(manage_roles=True)
|
||||
async def convocation(
|
||||
self,
|
||||
interaction: discord.Interaction,
|
||||
membre: discord.Member,
|
||||
raison: str,
|
||||
heure: str
|
||||
):
|
||||
role_convocation_id = 1388607106558726204
|
||||
log_user_ids = [
|
||||
1195440742307467377,
|
||||
689550504963080328,
|
||||
1359253046055534775
|
||||
]
|
||||
log_channel_id = 1389747212837322852
|
||||
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
try:
|
||||
roles_to_remove = [
|
||||
r for r in membre.roles if r.id != interaction.guild.id
|
||||
]
|
||||
await membre.remove_roles(*roles_to_remove)
|
||||
role_convocation = interaction.guild.get_role(role_convocation_id)
|
||||
if role_convocation:
|
||||
await membre.add_roles(role_convocation)
|
||||
|
||||
embed_convocation = discord.Embed(
|
||||
title="CONVOCATION | 🔖",
|
||||
description=f"> Bonjour <@{membre.id}>, vous êtes **convoqué** par <@{interaction.user.id}>. Voici les **détails** :",
|
||||
color=0x0099ff
|
||||
)
|
||||
embed_convocation.add_field(name="**Raison de la convocation :**", value=f"➜ {raison}", inline=False)
|
||||
embed_convocation.add_field(name="**Heure de la convocation :**", value=f"➜ {heure}", inline=False)
|
||||
embed_convocation.add_field(name="\u200B", value=(
|
||||
"> Merci de vous présenter dans le vocal attente moov **5 minutes** avant l’heure. "
|
||||
"Soyez **professionnel**, et en cas d’absence, merci de contacter la personne vous ayant convoqué.\n\n"
|
||||
"> La **levée** de suspension se fera uniquement à la **fin** de la convocation."
|
||||
), inline=False)
|
||||
embed_convocation.add_field(name="**__Bien cordialement__**", value="_La Gestion de Alésia | 📑_", inline=False)
|
||||
|
||||
embed_log = discord.Embed(
|
||||
title="📋 CONVOCATION ENVOYÉE",
|
||||
color=0xff9900
|
||||
)
|
||||
embed_log.add_field(name="👤 Membre convoqué", value=f"<@{membre.id}> ({membre.name}#{membre.discriminator})", inline=True)
|
||||
embed_log.add_field(name="👮 Convoqué par", value=f"<@{interaction.user.id}> ({interaction.user.name}#{interaction.user.discriminator})", inline=True)
|
||||
embed_log.add_field(name="📄 Raison", value=raison, inline=False)
|
||||
embed_log.add_field(name="🕒 Heure", value=heure, inline=False)
|
||||
embed_log.add_field(name="📆 Date", value=f"<t:{int(discord.utils.utcnow().timestamp())}:F>", inline=False)
|
||||
embed_log.set_footer(text="Gestion des convocations", icon_url=self.bot.user.display_avatar.url)
|
||||
|
||||
# MP au membre
|
||||
dm_sent = False
|
||||
try:
|
||||
await membre.send(embed=embed_convocation)
|
||||
dm_sent = True
|
||||
except:
|
||||
dm_sent = False
|
||||
|
||||
await interaction.edit_original_response(content=(
|
||||
f"✅ Convocation envoyée à {membre.mention}." if dm_sent else
|
||||
f"⚠️ Convocation enregistrée, mais impossible d'envoyer un MP à {membre.mention}."
|
||||
))
|
||||
|
||||
# Log aux utilisateurs
|
||||
for user_id in log_user_ids:
|
||||
try:
|
||||
user = await self.bot.fetch_user(user_id)
|
||||
await user.send(embed=embed_log)
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de l'envoi du log à {user_id} : {e}")
|
||||
|
||||
# Log dans le salon
|
||||
try:
|
||||
log_channel = await self.bot.fetch_channel(log_channel_id)
|
||||
if isinstance(log_channel, discord.TextChannel):
|
||||
await log_channel.send(embed=embed_log)
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de l'envoi du log dans le salon : {e}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Erreur dans la commande /convocation : {e}")
|
||||
await interaction.edit_original_response(content="❌ Une erreur est survenue.")
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Convocation(bot))
|
||||
|
|
@ -7,7 +7,7 @@ from typing import List
|
|||
|
||||
WHITELIST_FILE = "data/whitelist.json"
|
||||
|
||||
class Whitelist(commands.GroupCog, name="whitelist"):
|
||||
class Whitelist(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.whitelist = self.load_whitelist()
|
||||
|
|
@ -32,58 +32,95 @@ class Whitelist(commands.GroupCog, name="whitelist"):
|
|||
self.whitelist[str(guild_id)] = users
|
||||
self.save_whitelist()
|
||||
|
||||
@commands.hybrid_group(name="whitelist", aliases=["wl"], description="Gère la whitelist du serveur")
|
||||
async def whitelist_group(self, ctx):
|
||||
"""Groupe de commandes pour gérer la whitelist"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help(ctx.command)
|
||||
|
||||
# ✅ Ajouter un utilisateur
|
||||
@app_commands.command(name="ajouter", description="Ajoute un utilisateur à la whitelist")
|
||||
@whitelist_group.command(name="ajouter", description="Ajoute un utilisateur à la whitelist")
|
||||
@app_commands.describe(utilisateur="L'utilisateur à ajouter")
|
||||
async def ajouter(self, interaction: discord.Interaction, utilisateur: discord.User):
|
||||
guild_id = interaction.guild.id
|
||||
async def ajouter(self, ctx, utilisateur: discord.User):
|
||||
interaction = ctx.interaction
|
||||
guild_id = ctx.guild.id
|
||||
users = self._get_guild_whitelist(guild_id)
|
||||
user_id = str(utilisateur.id)
|
||||
|
||||
if user_id in users:
|
||||
await interaction.response.send_message(f"🔒 {utilisateur.mention} est déjà dans la whitelist.", ephemeral=True)
|
||||
msg = f"🔒 {utilisateur.mention} est déjà dans la whitelist."
|
||||
if interaction:
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
return
|
||||
|
||||
users.append(user_id)
|
||||
self._set_guild_whitelist(guild_id, users)
|
||||
await interaction.response.send_message(f"✅ {utilisateur.mention} a été ajouté à la whitelist.", ephemeral=True)
|
||||
msg = f"✅ {utilisateur.mention} a été ajouté à la whitelist."
|
||||
if interaction:
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
|
||||
# ❌ Retirer un utilisateur
|
||||
@app_commands.command(name="retirer", description="Retire un utilisateur de la whitelist")
|
||||
@whitelist_group.command(name="retirer", description="Retire un utilisateur de la whitelist")
|
||||
@app_commands.describe(utilisateur="L'utilisateur à retirer")
|
||||
async def retirer(self, interaction: discord.Interaction, utilisateur: discord.User):
|
||||
guild_id = interaction.guild.id
|
||||
async def retirer(self, ctx, utilisateur: discord.User):
|
||||
interaction = ctx.interaction
|
||||
guild_id = ctx.guild.id
|
||||
users = self._get_guild_whitelist(guild_id)
|
||||
user_id = str(utilisateur.id)
|
||||
|
||||
if user_id not in users:
|
||||
await interaction.response.send_message(f"⚠️ {utilisateur.mention} n'est pas dans la whitelist.", ephemeral=True)
|
||||
msg = f"⚠️ {utilisateur.mention} n'est pas dans la whitelist."
|
||||
if interaction:
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
return
|
||||
|
||||
users.remove(user_id)
|
||||
self._set_guild_whitelist(guild_id, users)
|
||||
await interaction.response.send_message(f"✅ {utilisateur.mention} a été retiré de la whitelist.", ephemeral=True)
|
||||
msg = f"✅ {utilisateur.mention} a été retiré de la whitelist."
|
||||
if interaction:
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
|
||||
# 📋 Voir la whitelist
|
||||
@app_commands.command(name="liste", description="Affiche les utilisateurs de la whitelist")
|
||||
async def liste(self, interaction: discord.Interaction):
|
||||
guild_id = interaction.guild.id
|
||||
@whitelist_group.command(name="liste", description="Affiche les utilisateurs de la whitelist")
|
||||
async def liste(self, ctx):
|
||||
interaction = ctx.interaction
|
||||
guild_id = ctx.guild.id
|
||||
users = self._get_guild_whitelist(guild_id)
|
||||
|
||||
if not users:
|
||||
await interaction.response.send_message("📭 La whitelist est vide pour ce serveur.", ephemeral=True)
|
||||
msg = "📭 La whitelist est vide pour ce serveur."
|
||||
if interaction:
|
||||
await interaction.response.send_message(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
return
|
||||
|
||||
# Defer if interaction because fetch_user might take time
|
||||
if interaction:
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
membres = []
|
||||
for user_id in users:
|
||||
try:
|
||||
utilisateur = await self.bot.fetch_user(int(user_id))
|
||||
membres.append(f"- {utilisateur.mention} ({utilisateur.name}#{utilisateur.discriminator})")
|
||||
membres.append(f"- {utilisateur.mention} ({utilisateur.name})")
|
||||
except discord.NotFound:
|
||||
membres.append(f"- <@{user_id}> (Utilisateur introuvable)")
|
||||
|
||||
texte = "\n".join(membres)
|
||||
await interaction.response.send_message(f"📃 **Utilisateurs whitelistés pour ce serveur :**\n{texte}", ephemeral=True)
|
||||
msg = f"📃 **Utilisateurs whitelistés pour ce serveur :**\n{texte}"
|
||||
if interaction:
|
||||
await interaction.followup.send(msg, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
|
||||
def is_whitelisted(self, guild_id: int, user_id: int) -> bool:
|
||||
"""Check if a user is whitelisted for a specific guild."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue