From c1cc28d6e8542a32c56254d756de2560c592c688 Mon Sep 17 00:00:00 2001 From: Mathis Date: Sat, 16 May 2026 18:36:03 +0200 Subject: [PATCH] =?UTF-8?q?nouvel=20correction=20du=20syst=C3=A8me=20d'abs?= =?UTF-8?q?ence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commandes/absence_staff.py | 57 ++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/commandes/absence_staff.py b/commandes/absence_staff.py index 18c924c..f9244f9 100755 --- a/commandes/absence_staff.py +++ b/commandes/absence_staff.py @@ -85,40 +85,43 @@ def parse_date(date_str: Optional[str]): class AbsenceModal(disnake.ui.Modal): def __init__(self, superieur: Optional[disnake.Member] = None): - super().__init__(title="Déclarer une Absence Staff", components=[self.motif, self.date_debut, self.date_fin]) self.superieur = superieur - - motif = disnake.ui.TextInput( - label="Motif de l'absence", - style=disnake.TextInputStyle.paragraph, - placeholder="Ex: Vacances, Raisons personnelles, Travail...", - required=True, - max_length=500 - ) - 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 = disnake.ui.TextInput( - label="Fin (JJ/MM/AAAA HH:MM)", - placeholder="Ex: 20/05/2024 18:00", - min_length=16, - max_length=16, - required=True - ) + self.motif_input = disnake.ui.TextInput( + label="Motif de l'absence", + style=disnake.TextInputStyle.paragraph, + placeholder="Ex: Vacances, Raisons personnelles, Travail...", + required=True, + max_length=500, + custom_id="absence_motif" + ) + self.debut_input = 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, + custom_id="absence_debut" + ) + self.fin_input = disnake.ui.TextInput( + label="Fin (JJ/MM/AAAA HH:MM)", + placeholder="Ex: 20/05/2024 18:00", + min_length=16, + max_length=16, + required=True, + custom_id="absence_fin" + ) + super().__init__(title="Déclarer une Absence Staff", components=[self.motif_input, self.debut_input, self.fin_input]) async def callback(self, interaction: disnake.ModalInteraction): try: - val_debut = interaction.text_values.get(self.date_debut.custom_id) or self.date_debut.value - val_fin = interaction.text_values.get(self.date_fin.custom_id) or self.date_fin.value + val_debut = interaction.text_values["absence_debut"] + val_fin = interaction.text_values["absence_fin"] + motif = interaction.text_values["absence_motif"] debut = parse_date(val_debut) fin = parse_date(val_fin) - except (ValueError, TypeError) as e: - return await interaction.response.send_message(f"❌ Format de date invalide ou manquant. Utilise le format: `{DATE_FORMAT.replace('%d', 'JJ').replace('%m', 'MM').replace('%Y', 'AAAA').replace('%H', 'HH').replace('%M', 'MM')}`", ephemeral=True) + except (ValueError, TypeError, KeyError) as e: + return await interaction.response.send_message(f"❌ Format de date invalide ou champ manquant. Utilise le format: `{DATE_FORMAT.replace('%d', 'JJ').replace('%m', 'MM').replace('%Y', 'AAAA').replace('%H', 'HH').replace('%M', 'MM')}`", ephemeral=True) if debut > fin: return await interaction.response.send_message("❌ La date de début doit précéder la date de fin.", ephemeral=True)