Migration de Kuby vers disnake

This commit is contained in:
Mathis 2026-05-06 17:07:09 +02:00
parent dc6e235f27
commit c8c579eefe
36 changed files with 1205 additions and 1253 deletions

View file

@ -1,6 +1,5 @@
import discord
from discord.ext import commands, tasks
from discord import app_commands, ui
import disnake
from disnake.ext import commands, tasks
import json
import asyncio
import os
@ -82,22 +81,26 @@ def parse_date(date_str: str):
# --- MODALS & VIEWS ---
class AbsenceModal(ui.Modal, title="Déclarer une Absence Staff"):
motif = ui.TextInput(
class AbsenceModal(disnake.ui.Modal):
def __init__(self, superieur: Optional[disnake.Member] = None):
super().__init__(title="Déclarer une Absence Staff")
self.superieur = superieur
motif = disnake.ui.TextInput(
label="Motif de l'absence",
style=discord.TextStyle.paragraph,
style=disnake.TextStyle.paragraph,
placeholder="Ex: Vacances, Raisons personnelles, Travail...",
required=True,
max_length=500
)
date_debut = ui.TextInput(
date_debut = disnake.ui.TextInput(
label="Début (JJ/MM/AAAA HH:MM)",
placeholder="Ex: 15/05/2024 08:00",
min_length=16,
max_length=16,
required=True
)
date_fin = ui.TextInput(
date_fin = disnake.ui.TextInput(
label="Fin (JJ/MM/AAAA HH:MM)",
placeholder="Ex: 20/05/2024 18:00",
min_length=16,
@ -105,11 +108,7 @@ class AbsenceModal(ui.Modal, title="Déclarer une Absence Staff"):
required=True
)
def __init__(self, superieur: Optional[discord.Member] = None):
super().__init__()
self.superieur = superieur
async def on_submit(self, interaction: discord.Interaction):
async def callback(self, interaction: disnake.Interaction):
try:
debut = parse_date(self.date_debut.value)
fin = parse_date(self.date_fin.value)
@ -182,20 +181,20 @@ class AbsenceModal(ui.Modal, title="Déclarer une Absence Staff"):
await interaction.response.send_message("✅ Absence enregistrée avec succès !", ephemeral=True)
class AbsenceConfigView(ui.View):
class AbsenceConfigView(disnake.ui.View):
def __init__(self, guild_id: int):
super().__init__(timeout=60)
self.guild_id = guild_id
@ui.button(label="Définir le Salon", style=discord.ButtonStyle.primary, emoji="📁")
async def set_channel(self, interaction: discord.Interaction, button: ui.Button):
@disnake.ui.button(label="Définir le Salon", style=disnake.ButtonStyle.primary, emoji="📁")
async def set_channel(self, interaction: disnake.Interaction, button: disnake.ui.Button):
await interaction.response.send_message("Mentionne le salon ici (ou envoie son ID) :", ephemeral=True)
def check(m):
return m.author == interaction.user and m.channel == interaction.channel
try:
msg = await interaction.client.wait_for('message', check=check, timeout=30)
msg = await interaction.bot.wait_for('message', check=check, timeout=30)
channel = None
if msg.channel_mentions:
channel = msg.channel_mentions[0]
@ -214,15 +213,15 @@ class AbsenceConfigView(ui.View):
except asyncio.TimeoutError:
await interaction.followup.send("❌ Temps écoulé.", ephemeral=True)
@ui.button(label="Définir le Rôle", style=discord.ButtonStyle.primary, emoji="🎭")
async def set_role(self, interaction: discord.Interaction, button: ui.Button):
@disnake.ui.button(label="Définir le Rôle", style=disnake.ButtonStyle.primary, emoji="🎭")
async def set_role(self, interaction: disnake.Interaction, button: disnake.ui.Button):
await interaction.response.send_message("Mentionne le rôle ici (ou envoie son ID) :", ephemeral=True)
def check(m):
return m.author == interaction.user and m.channel == interaction.channel
try:
msg = await interaction.client.wait_for('message', check=check, timeout=30)
msg = await interaction.bot.wait_for('message', check=check, timeout=30)
role = None
if msg.role_mentions:
role = msg.role_mentions[0]
@ -246,22 +245,22 @@ class Absence(commands.Cog):
self.bot = bot
self.check_absences.start()
@app_commands.command(name="absence", description="Déclarer une absence staff")
@app_commands.describe(superieur="Le supérieur hiérarchique à prévenir")
async def absence(self, interaction: discord.Interaction, superieur: Optional[discord.Member] = None):
@commands.slash_command(name="absence", description="Déclarer une absence staff")
async def absence(self, interaction: disnake.ApplicationCommandInteraction,
superieur: Optional[disnake.Member] = commands.Param(None, description="Le supérieur hiérarchique à prévenir")):
"""Déclare une absence via un formulaire"""
await interaction.response.send_modal(AbsenceModal(superieur))
@app_commands.command(name="absence_config", description="Configurer le système d'absence (Admin)")
@app_commands.checks.has_permissions(administrator=True)
async def absence_config(self, interaction: discord.Interaction):
@commands.slash_command(name="absence_config", description="Configurer le système d'absence (Admin)")
@commands.has_permissions(administrator=True)
async def absence_config(self, interaction: disnake.ApplicationCommandInteraction):
"""Ouvre le panneau de configuration des absences"""
settings = load_settings(interaction.guild.id)
embed = discord.Embed(
embed = disnake.Embed(
title="⚙️ Configuration des Absences Staff",
description="Utilisez les boutons ci-dessous pour configurer le système.",
color=discord.Color.blue()
color=disnake.Color.blue()
)
channel_id = settings.get("absence_channel_id")
@ -280,7 +279,7 @@ class Absence(commands.Cog):
await interaction.response.send_message(embed=embed, view=AbsenceConfigView(interaction.guild.id), ephemeral=True)
async def strike_absence_message(self, guild: discord.Guild, channel_id: int, message_id: int):
async def strike_absence_message(self, guild: disnake.Guild, channel_id: int, message_id: int):
"""Modifie le message d'absence pour le barrer au lieu de le supprimer"""
channel = guild.get_channel(channel_id)
if not channel:
@ -311,8 +310,8 @@ class Absence(commands.Cog):
except Exception as e:
print(f"Erreur lors du barrage du message d'absence: {e}")
@app_commands.command(name="fin_absence", description="Terminer son absence staff")
async def fin_absence(self, interaction: discord.Interaction):
@commands.slash_command(name="fin_absence", description="Terminer son absence staff")
async def fin_absence(self, interaction: disnake.ApplicationCommandInteraction):
"""Met fin à l'absence en cours"""
all_abs = await load_absences()
guild_abs = get_guild_absences(all_abs, interaction.guild.id)
@ -343,8 +342,8 @@ class Absence(commands.Cog):
await save_absences(all_abs)
await interaction.response.send_message("✅ Ton absence a été retirée.", ephemeral=True)
@app_commands.command(name="liste_absences", description="Afficher la liste des absences staff en cours")
async def liste_absences(self, interaction: discord.Interaction):
@commands.slash_command(name="liste_absences", description="Afficher la liste des absences staff en cours")
async def liste_absences(self, interaction: disnake.ApplicationCommandInteraction):
"""Affiche les absences en cours sur le serveur"""
all_abs = await load_absences()
guild_abs = get_guild_absences(all_abs, interaction.guild.id)
@ -360,10 +359,10 @@ class Absence(commands.Cog):
per_page = 5
pages = [absences[i:i + per_page] for i in range(0, len(absences), per_page)]
def create_embed(page_index: int) -> discord.Embed:
embed = discord.Embed(
def create_embed(page_index: int) -> disnake.Embed:
embed = disnake.Embed(
title=f"📋 Absences staff - {interaction.guild.name} ({page_index + 1}/{len(pages)})",
color=discord.Color.orange()
color=disnake.Color.orange()
)
for user_id, info in pages[page_index]:
embed.add_field(
@ -378,19 +377,19 @@ class Absence(commands.Cog):
embed.set_footer(text="Gestion des absences du staff")
return embed
class PaginatorView(ui.View):
class PaginatorView(disnake.ui.View):
def __init__(self):
super().__init__(timeout=60)
self.page = 0
@ui.button(label="⬅️ Précédent", style=discord.ButtonStyle.secondary, disabled=True)
async def previous(self, interaction_btn: discord.Interaction, button: discord.ui.Button):
@disnake.ui.button(label="⬅️ Précédent", style=disnake.ButtonStyle.secondary, disabled=True)
async def previous(self, interaction_btn: disnake.Interaction, button: disnake.ui.Button):
self.page -= 1
self.update_buttons()
await interaction_btn.response.edit_message(embed=create_embed(self.page), view=self)
@ui.button(label="➡️ Suivant", style=discord.ButtonStyle.secondary, disabled=len(pages) == 1)
async def next(self, interaction_btn: discord.Interaction, button: discord.ui.Button):
@disnake.ui.button(label="➡️ Suivant", style=disnake.ButtonStyle.secondary, disabled=len(pages) == 1)
async def next(self, interaction_btn: disnake.Interaction, button: disnake.ui.Button):
self.page += 1
self.update_buttons()
await interaction_btn.response.edit_message(embed=create_embed(self.page), view=self)