Migration de Kuby vers disnake
This commit is contained in:
parent
dc6e235f27
commit
c8c579eefe
36 changed files with 1205 additions and 1253 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import app_commands
|
||||
import disnake
|
||||
from disnake.ext import commands
|
||||
import json
|
||||
import os
|
||||
from typing import List, Optional, Dict
|
||||
|
|
@ -52,20 +51,17 @@ class Convocation(commands.Cog):
|
|||
del self.backups[key]
|
||||
save_json(CONV_BACKUPS_FILE, self.backups)
|
||||
|
||||
@commands.hybrid_group(name="convocation", description="Gère les convocations de membres")
|
||||
@commands.slash_command(name="convocation", description="Gère les convocations de membres")
|
||||
@commands.has_permissions(manage_roles=True)
|
||||
async def convocation_group(self, ctx):
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help(ctx.command)
|
||||
async def convocation_group(self, interaction: disnake.ApplicationCommandInteraction):
|
||||
pass
|
||||
|
||||
@convocation_group.command(name="convoquer", description="Convoque un membre et verrouille ses accès")
|
||||
@app_commands.describe(
|
||||
membre="Le membre à convoquer",
|
||||
raison="La raison de la convocation",
|
||||
heure="L'heure de la convocation (ex: 14:30)"
|
||||
)
|
||||
async def convoquer(self, ctx, membre: discord.Member, raison: str, heure: str):
|
||||
guild_id = ctx.guild.id
|
||||
@convocation_group.sub_command(name="convoquer", description="Convoque un membre et verrouille ses accès")
|
||||
async def convoquer(self, interaction: disnake.ApplicationCommandInteraction,
|
||||
membre: disnake.Member = commands.Param(description="Le membre à convoquer"),
|
||||
raison: str = commands.Param(description="La raison de la convocation"),
|
||||
heure: str = commands.Param(description="L'heure de la convocation (ex: 14:30)")):
|
||||
guild_id = interaction.guild.id
|
||||
settings = self.get_guild_settings(guild_id)
|
||||
role_conv_id = settings.get("role_id")
|
||||
log_channel_id = settings.get("log_channel_id")
|
||||
|
|
@ -73,30 +69,30 @@ class Convocation(commands.Cog):
|
|||
admin_ids = settings.get("admin_ids", [])
|
||||
|
||||
if not role_conv_id:
|
||||
await ctx.send("❌ Le rôle de convocation n'est pas configuré. Utilisez `/convocation config`.", ephemeral=True)
|
||||
await interaction.response.send_message("❌ Le rôle de convocation n'est pas configuré. Utilisez `/convocation config`.", ephemeral=True)
|
||||
return
|
||||
|
||||
await ctx.defer(ephemeral=True)
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
try:
|
||||
# --- BACKUP ---
|
||||
bot_top_role = ctx.guild.me.top_role
|
||||
bot_top_role = interaction.guild.me.top_role
|
||||
backup_data = {
|
||||
"roles": [r.id for r in membre.roles if not r.is_default() and r.id != role_conv_id and r.position < bot_top_role.position],
|
||||
"overrides": {}
|
||||
}
|
||||
|
||||
# 1. Backup and Remove current roles
|
||||
current_roles = [ctx.guild.get_role(rid) for rid in backup_data["roles"] if ctx.guild.get_role(rid)]
|
||||
current_roles = [interaction.guild.get_role(rid) for rid in backup_data["roles"] if interaction.guild.get_role(rid)]
|
||||
if current_roles:
|
||||
try:
|
||||
await membre.remove_roles(*current_roles, reason=f"Convocation par {ctx.author}")
|
||||
except discord.Forbidden:
|
||||
await ctx.send("⚠️ Je n'ai pas pu retirer certains rôles (Permission refusée).", ephemeral=True)
|
||||
await membre.remove_roles(*current_roles, reason=f"Convocation par {interaction.author}")
|
||||
except disnake.Forbidden:
|
||||
await interaction.followup.send("⚠️ Je n'ai pas pu retirer certains rôles (Permission refusée).", ephemeral=True)
|
||||
|
||||
# 2. Dynamic Lockdown: Loop through ALL channels
|
||||
lockdown_count = 0
|
||||
for channel in ctx.guild.channels:
|
||||
for channel in interaction.guild.channels:
|
||||
# On ignore le salon d'attente et ses parents s'il y en a
|
||||
if attente_id and (channel.id == attente_id or (hasattr(channel, 'category') and channel.category and channel.category.id == attente_id)):
|
||||
continue
|
||||
|
|
@ -112,28 +108,28 @@ class Convocation(commands.Cog):
|
|||
# Specific override for this member: View Channel = False
|
||||
await channel.set_permissions(membre, view_channel=False, reason="Convocation Lockdown")
|
||||
lockdown_count += 1
|
||||
except discord.Forbidden:
|
||||
except disnake.Forbidden:
|
||||
pass # Skip if we can't touch this channel
|
||||
|
||||
self.save_backup(guild_id, membre.id, backup_data)
|
||||
|
||||
# 3. Add Convocation role
|
||||
role_conv = ctx.guild.get_role(role_conv_id)
|
||||
role_conv = interaction.guild.get_role(role_conv_id)
|
||||
if role_conv:
|
||||
if role_conv.position >= bot_top_role.position:
|
||||
await ctx.send(f"⚠️ Je ne peux pas donner le rôle {role_conv.mention} car il est plus haut que moi !", ephemeral=True)
|
||||
await interaction.followup.send(f"⚠️ Je ne peux pas donner le rôle {role_conv.mention} car il est plus haut que moi !", ephemeral=True)
|
||||
else:
|
||||
try:
|
||||
await membre.add_roles(role_conv, reason="Début de convocation")
|
||||
except discord.Forbidden:
|
||||
await ctx.send(f"⚠️ Impossible de donner le rôle {role_conv.name} (Permission refusée).", ephemeral=True)
|
||||
except disnake.Forbidden:
|
||||
await interaction.followup.send(f"⚠️ Impossible de donner le rôle {role_conv.name} (Permission refusée).", ephemeral=True)
|
||||
|
||||
# 4. Embeds & Logs (Inchangés mais inclus pour la cohérence)
|
||||
embed_conv = discord.Embed(
|
||||
embed_conv = disnake.Embed(
|
||||
title="CONVOCATION | 🔖",
|
||||
description=f"> Bonjour {membre.mention}, vous êtes **convoqué** par {ctx.author.mention}. Voici les **détails** :",
|
||||
description=f"> Bonjour {membre.mention}, vous êtes **convoqué** par {interaction.author.mention}. Voici les **détails** :",
|
||||
color=0x0099ff,
|
||||
timestamp=discord.utils.utcnow()
|
||||
timestamp=disnake.utils.utcnow()
|
||||
)
|
||||
embed_conv.add_field(name="**Raison de la convocation :**", value=f"➜ {raison}", inline=False)
|
||||
embed_conv.add_field(name="**Heure de la convocation :**", value=f"➜ {heure}", inline=False)
|
||||
|
|
@ -141,15 +137,15 @@ class Convocation(commands.Cog):
|
|||
"> Merci de vous présenter dans le vocal attente **5 minutes** avant l'heure.\n\n"
|
||||
"> La **levée** de suspension se fera uniquement à la **fin** de la convocation."
|
||||
), inline=False)
|
||||
embed_conv.set_footer(text=f"Gestion de {ctx.guild.name}")
|
||||
embed_conv.set_footer(text=f"Gestion de {interaction.guild.name}")
|
||||
|
||||
embed_log = discord.Embed(
|
||||
embed_log = disnake.Embed(
|
||||
title="📋 CONVOCATION ENVOYÉE",
|
||||
color=0xff9900,
|
||||
timestamp=discord.utils.utcnow()
|
||||
timestamp=disnake.utils.utcnow()
|
||||
)
|
||||
embed_log.add_field(name="👤 Membre convoqué", value=f"{membre.mention} ({membre.id})", inline=True)
|
||||
embed_log.add_field(name="👮 Convoqué par", value=f"{ctx.author.mention}", inline=True)
|
||||
embed_log.add_field(name="👮 Convoqué par", value=f"{interaction.author.mention}", inline=True)
|
||||
embed_log.add_field(name="📄 Raison", value=raison, inline=False)
|
||||
embed_log.add_field(name="🕒 Heure", value=heure, inline=False)
|
||||
|
||||
|
|
@ -158,7 +154,7 @@ class Convocation(commands.Cog):
|
|||
try:
|
||||
await membre.send(embed=embed_conv)
|
||||
dm_sent = True
|
||||
except discord.Forbidden:
|
||||
except disnake.Forbidden:
|
||||
dm_sent = False
|
||||
|
||||
# Admin & Channel Logs
|
||||
|
|
@ -169,47 +165,47 @@ class Convocation(commands.Cog):
|
|||
except: pass
|
||||
|
||||
if log_channel_id:
|
||||
chan = ctx.guild.get_channel(log_channel_id)
|
||||
chan = interaction.guild.get_channel(log_channel_id)
|
||||
if chan: await chan.send(embed=embed_log)
|
||||
|
||||
await ctx.send(f"✅ Convocation envoyée à {membre.mention}. ({lockdown_count} salons verrouillés) " +
|
||||
await interaction.followup.send(f"✅ Convocation envoyée à {membre.mention}. ({lockdown_count} salons verrouillés) " +
|
||||
("" if dm_sent else "(⚠️ DM impossible)"), ephemeral=True)
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
await ctx.send(f"❌ Une erreur critique est survenue : {e}", ephemeral=True)
|
||||
await interaction.followup.send(f"❌ Une erreur critique est survenue : {e}", ephemeral=True)
|
||||
|
||||
@convocation_group.command(name="lever", description="Lève la convocation d'un membre et restaure ses accès")
|
||||
@app_commands.describe(membre="Le membre à libérer")
|
||||
async def lever(self, ctx, membre: discord.Member):
|
||||
guild_id = ctx.guild.id
|
||||
@convocation_group.sub_command(name="lever", description="Lève la convocation d'un membre et restaure ses accès")
|
||||
async def lever(self, interaction: disnake.ApplicationCommandInteraction,
|
||||
membre: disnake.Member = commands.Param(description="Le membre à libérer")):
|
||||
guild_id = interaction.guild.id
|
||||
settings = self.get_guild_settings(guild_id)
|
||||
role_conv_id = settings.get("role_id")
|
||||
|
||||
await ctx.defer(ephemeral=True)
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
backup_data = self.get_backup(guild_id, membre.id)
|
||||
if not backup_data:
|
||||
await ctx.send("⚠️ Aucune donnée de convocation trouvée pour ce membre.", ephemeral=True)
|
||||
await interaction.followup.send("⚠️ Aucune donnée de convocation trouvée pour ce membre.", ephemeral=True)
|
||||
return
|
||||
|
||||
# 1. Remove Convocation role
|
||||
if role_conv_id:
|
||||
role_conv = ctx.guild.get_role(role_conv_id)
|
||||
role_conv = interaction.guild.get_role(role_conv_id)
|
||||
if role_conv and role_conv in membre.roles:
|
||||
await membre.remove_roles(role_conv, reason="Fin de convocation")
|
||||
|
||||
# 2. Restore channel overrides
|
||||
restore_count = 0
|
||||
overrides = backup_data.get("overrides", {})
|
||||
for channel in ctx.guild.channels:
|
||||
for channel in interaction.guild.channels:
|
||||
chan_id_str = str(channel.id)
|
||||
try:
|
||||
if chan_id_str in overrides:
|
||||
# Restore previous override
|
||||
ov_data = overrides[chan_id_str]
|
||||
overwrite = discord.PermissionOverwrite(**ov_data)
|
||||
overwrite = disnake.PermissionOverwrite(**ov_data)
|
||||
await channel.set_permissions(membre, overwrite=overwrite, reason="Restauration fin de convocation")
|
||||
restore_count += 1
|
||||
else:
|
||||
|
|
@ -217,7 +213,7 @@ class Convocation(commands.Cog):
|
|||
# On ne vide que si un override membre existait (sinon on risque de supprimer des perms rôles ?)
|
||||
# En fait set_permissions(member, overwrite=None) supprime l'entrée PERSONNELLE du membre.
|
||||
await channel.set_permissions(membre, overwrite=None, reason="Fin de convocation - Cleanup")
|
||||
except discord.Forbidden:
|
||||
except disnake.Forbidden:
|
||||
pass
|
||||
|
||||
# 3. Restore roles
|
||||
|
|
@ -225,8 +221,8 @@ class Convocation(commands.Cog):
|
|||
restored_roles = []
|
||||
if role_ids:
|
||||
for rid in role_ids:
|
||||
role = ctx.guild.get_role(rid)
|
||||
if role and role.position < ctx.guild.me.top_role.position:
|
||||
role = interaction.guild.get_role(rid)
|
||||
if role and role.position < interaction.guild.me.top_role.position:
|
||||
restored_roles.append(role)
|
||||
|
||||
if restored_roles:
|
||||
|
|
@ -235,27 +231,24 @@ class Convocation(commands.Cog):
|
|||
self.clear_backup(guild_id, membre.id)
|
||||
|
||||
# 4. Notification
|
||||
embed = discord.Embed(
|
||||
embed = disnake.Embed(
|
||||
title="🔓 CONVOCATION TERMINÉE",
|
||||
description=f"Votre convocation sur **{ctx.guild.name}** est terminée. Vos accès ont été restaurés.",
|
||||
color=discord.Color.green()
|
||||
description=f"Votre convocation sur **{interaction.guild.name}** est terminée. Vos accès ont été restaurés.",
|
||||
color=disnake.Color.green()
|
||||
)
|
||||
try:
|
||||
await membre.send(embed=embed)
|
||||
except: pass
|
||||
|
||||
await ctx.send(f"✅ Convocation levée pour {membre.mention}. Access restaurés.", ephemeral=True)
|
||||
await interaction.followup.send(f"✅ Convocation levée pour {membre.mention}. Access restaurés.", ephemeral=True)
|
||||
|
||||
@convocation_group.command(name="config", description="Configure le système de convocation")
|
||||
@app_commands.describe(
|
||||
role="Le rôle de convocation (Muet/Convocation)",
|
||||
channel="Le salon de logs",
|
||||
attente="Salon (ou catégorie) d'attente à laisser visible",
|
||||
admins="Liste d'IDs d'admins à notifier (séparés par des espaces)"
|
||||
)
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def config(self, ctx, role: discord.Role, channel: discord.TextChannel = None, attente: discord.abc.GuildChannel = None, admins: str = None):
|
||||
guild_id = ctx.guild.id
|
||||
@convocation_group.sub_command(name="config", description="Configure le système de convocation")
|
||||
async def config(self, interaction: disnake.ApplicationCommandInteraction,
|
||||
role: disnake.Role = commands.Param(description="Le rôle de convocation (Muet/Convocation)"),
|
||||
channel: disnake.TextChannel = commands.Param(None, description="Le salon de logs"),
|
||||
attente: disnake.abc.GuildChannel = commands.Param(None, description="Salon (ou catégorie) d'attente à laisser visible"),
|
||||
admins: str = commands.Param(None, description="Liste d'IDs d'admins à notifier (séparés par des espaces)")):
|
||||
guild_id = interaction.guild.id
|
||||
settings = self.get_guild_settings(guild_id)
|
||||
|
||||
settings["role_id"] = role.id
|
||||
|
|
@ -273,13 +266,13 @@ class Convocation(commands.Cog):
|
|||
|
||||
self.save_guild_settings(guild_id, settings)
|
||||
|
||||
embed = discord.Embed(title="⚙️ Configuration Convocation Mise à jour", color=discord.Color.blue())
|
||||
embed = disnake.Embed(title="⚙️ Configuration Convocation Mise à jour", color=disnake.Color.blue())
|
||||
embed.add_field(name="Rôle", value=role.mention)
|
||||
embed.add_field(name="Salon Logs", value=channel.mention if channel else "Non défini")
|
||||
embed.add_field(name="Salon/Cat d'attente", value=attente.mention if attente else "Non défini")
|
||||
embed.add_field(name="Admins notifiés", value=str(len(settings.get("admin_ids", []))))
|
||||
|
||||
await ctx.send(embed=embed, ephemeral=True)
|
||||
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Convocation(bot))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue