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 import app_commands
from discord.ext import commands
import disnake
from disnake.ext import commands
from utils.gitlab_client import gitlab_client
from aiohttp import web
import logging
@ -33,27 +32,27 @@ def save_report(issue_iid, user_id):
except Exception as e:
kuby_logger.error(f"Error saving report to JSON: {e}")
class BugReportModal(discord.ui.Modal, title="Signaler un Bug"):
class BugReportModal(disnake.ui.Modal):
def __init__(self, priority_choice):
super().__init__()
super().__init__(title="Signaler un Bug")
self.priority_choice = priority_choice
bug_title = discord.ui.TextInput(
bug_title = disnake.ui.TextInput(
label="Titre du bug",
placeholder="Décrivez brièvement le problème...",
required=True,
max_length=100
)
description = discord.ui.TextInput(
description = disnake.ui.TextInput(
label="Description détaillée",
style=discord.TextStyle.paragraph,
style=disnake.TextStyle.paragraph,
placeholder="Que s'est-il passé ? Comment reproduire le bug ?",
required=True,
max_length=1000
)
async def on_submit(self, interaction: discord.Interaction):
async def callback(self, interaction: disnake.Interaction):
await interaction.response.send_message("Envoi de votre rapport de bug à GitLab...", ephemeral=True)
description_text = f"**Rapporté par:** {interaction.user} ({interaction.user.id})\n"
@ -76,23 +75,26 @@ class BugReportModal(discord.ui.Modal, title="Signaler un Bug"):
else:
await interaction.edit_original_response(content="❌ Une erreur est survenue lors de l'envoi du rapport à GitLab. Veuillez contacter un administrateur.")
class FeatureSuggestionModal(discord.ui.Modal, title="Suggérer une fonctionnalité"):
suggestion_title = discord.ui.TextInput(
class FeatureSuggestionModal(disnake.ui.Modal):
def __init__(self):
super().__init__(title="Suggérer une fonctionnalité")
suggestion_title = disnake.ui.TextInput(
label="Titre de la suggestion",
placeholder="Que voulez-vous ajouter ?",
required=True,
max_length=100
)
description = discord.ui.TextInput(
description = disnake.ui.TextInput(
label="Détails de la fonctionnalité",
style=discord.TextStyle.paragraph,
style=disnake.TextStyle.paragraph,
placeholder="Décrivez comment cela devrait fonctionner...",
required=True,
max_length=1000
)
async def on_submit(self, interaction: discord.Interaction):
async def callback(self, interaction: disnake.Interaction):
await interaction.response.send_message("Envoi de votre suggestion à GitLab...", ephemeral=True)
description_text = f"**Suggéré par:** {interaction.user} ({interaction.user.id})\n\n"
@ -231,10 +233,10 @@ class BugReport(commands.Cog):
try:
# Création de l'embed pour la mise à jour de statut
embed = discord.Embed(
embed = disnake.Embed(
title="🛠️ Mise à jour de votre signalement !",
description=f"Le statut de votre rapport **{issue_title}** a été mis à jour par l'équipe.",
color=discord.Color.blue()
color=disnake.Color.blue()
)
embed.add_field(name="Nouveaux Labels / Statuts", value=current_labels_str)
@ -244,7 +246,7 @@ class BugReport(commands.Cog):
kuby_logger.info(f"Notification de label envoyée à {user} ({user.id}) pour l'issue #{issue_iid}")
if dev and dev.id != user.id:
await dev.send(f"✅ [SUIVI] L'utilisateur {user} ({user.id}) a bien reçu la notification de statut **{current_labels_str}** pour l'issue #{issue_iid} ({issue_title}).")
except discord.Forbidden:
except disnake.Forbidden:
kuby_logger.warning(f"Impossible d'envoyer un MP à {user} ({user.id}) - MPs désactivés.")
if dev and dev.id != user.id:
await dev.send(f"⚠️ [DM BLOQUÉ] {user} ({user.id}) a ses MPs fermés. Impossible de notifier pour l'issue #{issue_iid}.")
@ -259,10 +261,10 @@ class BugReport(commands.Cog):
if is_closing_now:
try:
embed = discord.Embed(
embed = disnake.Embed(
title="🛠️ Bug / Suggestion Terminé(e) !",
description=f"Bonne nouvelle ! Votre signalement **{issue_title}** a été marqué comme terminé ou résolu.",
color=discord.Color.green()
color=disnake.Color.green()
)
embed.add_field(name="Prochaine étape", value="La mise à jour arrive prochainement (ou est déjà là) !")
embed.set_footer(text="Merci pour votre aide !")
@ -272,7 +274,7 @@ class BugReport(commands.Cog):
kuby_logger.info(f"Notification de clôture envoyée à {user} ({user.id}) pour l'issue #{issue_iid}")
if dev and dev.id != user.id:
await dev.send(f"✅ [SUIVI] L'utilisateur {user} ({user.id}) a bien reçu la notification de CLÔTURE pour l'issue #{issue_iid}.")
except discord.Forbidden:
except disnake.Forbidden:
kuby_logger.warning(f"Impossible d'envoyer le MP de clôture à {user} ({user.id}).")
if dev and dev.id != user.id:
await dev.send(f"⚠️ [DM BLOQUÉ] Impossible d'annoncer la clôture à {user} ({user.id}) pour l'issue #{issue_iid} (DMs désactivés).")
@ -290,10 +292,10 @@ class BugReport(commands.Cog):
author_name = payload.get("user", {}).get("name", "Développeur")
try:
embed = discord.Embed(
embed = disnake.Embed(
title="💬 Nouveau commentaire sur votre signalement",
description=f"Le développeur a répondu à votre rapport **{issue_title}** :\n\n>>> {note_body}",
color=discord.Color.orange()
color=disnake.Color.orange()
)
embed.set_footer(text=f"Par {author_name}")
@ -302,7 +304,7 @@ class BugReport(commands.Cog):
kuby_logger.info(f"Commentaire GitLab envoyé à {user} ({user.id}) pour l'issue #{issue_iid}")
if dev and dev.id != user.id:
await dev.send(f"✅ [SUIVI] L'utilisateur {user} ({user.id}) a bien reçu votre commentaire pour l'issue #{issue_iid}.")
except discord.Forbidden:
except disnake.Forbidden:
kuby_logger.warning(f"Impossible d'envoyer le commentaire en MP à {user} ({user.id}).")
if dev and dev.id != user.id:
await dev.send(f"⚠️ [DM BLOQUÉ] Impossible d'envoyer votre commentaire à {user} ({user.id}) pour l'issue #{issue_iid} (DMs désactivés).")
@ -317,18 +319,19 @@ class BugReport(commands.Cog):
kuby_logger.error(f"Error handling bot event: {e}")
return web.json_response({"status": "error", "message": str(e)}, status=500)
@app_commands.command(name="signaler_bug", description="Signaler un bug aux développeurs")
@app_commands.choices(priority=[
app_commands.Choice(name="Basse", value="Low"),
app_commands.Choice(name="Normale", value="Normal"),
app_commands.Choice(name="Haute", value="High"),
app_commands.Choice(name="Urgente", value="Urgent"),
])
async def signaler_bug(self, interaction: discord.Interaction, priority: app_commands.Choice[str]):
await interaction.response.send_modal(BugReportModal(priority))
@commands.slash_command(name="signaler_bug", description="Signaler un bug aux développeurs")
async def signaler_bug(self, interaction: disnake.ApplicationCommandInteraction,
priority: str = commands.Param(description="Priorité du bug", choices={"Basse": "Low", "Normale": "Normal", "Haute": "High", "Urgente": "Urgent"})):
# Simulate app_commands.Choice behavior for existing code
from collections import namedtuple
Choice = namedtuple('Choice', ['name', 'value'])
# find the name from the value
p_name = [k for k, v in {"Basse": "Low", "Normale": "Normal", "Haute": "High", "Urgente": "Urgent"}.items() if v == priority][0]
choice = Choice(name=p_name, value=priority)
await interaction.response.send_modal(BugReportModal(choice))
@app_commands.command(name="suggerer_fonctionnalite", description="Proposer une nouvelle fonctionnalité pour le bot")
async def suggerer_fonctionnalite(self, interaction: discord.Interaction):
@commands.slash_command(name="suggerer_fonctionnalite", description="Proposer une nouvelle fonctionnalité pour le bot")
async def suggerer_fonctionnalite(self, interaction: disnake.ApplicationCommandInteraction):
await interaction.response.send_modal(FeatureSuggestionModal())
async def setup(bot):