fix(ticket): move command group inside Cog class for proper sync
All checks were successful
ci / ci (push) Successful in 46s

This commit is contained in:
Mathis 2026-09-20 20:13:07 +02:00
parent 57b6f09dd7
commit 80daeae55c

View file

@ -13,16 +13,6 @@ from tickets.ui import PanelCreateButton
logger = logging.getLogger("vision") logger = logging.getLogger("vision")
class TicketSystem(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.bot.add_view(PanelView())
@commands.Cog.listener()
async def on_ready(self):
logger.info("TicketSystem cog charge")
class PanelView(discord.ui.LayoutView): class PanelView(discord.ui.LayoutView):
def __init__(self): def __init__(self):
super().__init__(timeout=None) super().__init__(timeout=None)
@ -39,121 +29,6 @@ class PanelView(discord.ui.LayoutView):
self.add_item(container) self.add_item(container)
ticket_group = app_commands.Group(name="ticket", description="Systeme de tickets")
@ticket_group.command(name="setup", description="Envoyer le panneau de tickets")
@app_commands.describe(channel="Canal pour le panneau")
@app_commands.checks.has_permissions(manage_guild=True)
async def ticket_setup(interaction: discord.Interaction, channel: discord.TextChannel):
config = storage.get_config(interaction.guild_id)
config.enabled = True
config.panel_channel_id = channel.id
storage.save_config(config)
view = PanelView()
msg = await channel.send(view=view)
config.panel_message_id = msg.id
storage.save_config(config)
container = discord.ui.Container()
container.add_item(discord.ui.TextDisplay(f"## Panneau envoye\nCanal : {channel.mention}\nStatut : Actif"))
resp_view = discord.ui.LayoutView()
resp_view.add_item(container)
await interaction.response.send_message(view=resp_view, ephemeral=True)
@ticket_group.command(name="config", description="Configuration du systeme de tickets")
@app_commands.checks.has_permissions(manage_guild=True)
async def ticket_config(interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id)
cats = "\n".join(f"- {c.emoji} **{c.name}**" for c in config.categories) or "*Aucune*"
container = discord.ui.Container()
container.add_item(
discord.ui.TextDisplay(
f"## Configuration Tickets\n"
f"**Statut :** {'🟢 Actif' if config.enabled else '🔴 Inactif'}\n"
f"**Role staff :** <@&{config.staff_role_id}>\n"
if config.staff_role_id
else f"**Canal de logs :** <#{config.log_channel_id}>\n"
if config.log_channel_id
else f"### Categories\n{cats}"
)
)
container.add_item(discord.ui.Separator())
container.add_item(
discord.ui.ActionRow(
ConfigToggleButton(config.enabled),
ConfigAddCatButton(),
ConfigSetStaffButton(),
ConfigSetLogButton(),
)
)
view = discord.ui.LayoutView()
view.add_item(container)
await interaction.response.send_message(view=view, ephemeral=True)
class ConfigToggleButton(discord.ui.Button):
def __init__(self, enabled: bool):
super().__init__(
label="Desactiver" if enabled else "Activer",
style=discord.ButtonStyle.danger if enabled else discord.ButtonStyle.success,
custom_id="ticket_cfg_toggle",
)
async def callback(self, interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id)
config.enabled = not config.enabled
storage.save_config(config)
await interaction.response.edit_message(view=ConfigView())
class ConfigAddCatButton(discord.ui.Button):
def __init__(self):
super().__init__(
label="Ajouter categorie",
style=discord.ButtonStyle.primary,
custom_id="ticket_cfg_addcat",
)
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_modal(AddCategoryModal())
class ConfigSetStaffButton(discord.ui.Button):
def __init__(self):
super().__init__(
label="Role staff",
style=discord.ButtonStyle.secondary,
custom_id="ticket_cfg_staff",
)
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_message(
"Selectionnez le role staff :",
view=StaffRoleSelectView(),
ephemeral=True,
)
class ConfigSetLogButton(discord.ui.Button):
def __init__(self):
super().__init__(
label="Canal logs",
style=discord.ButtonStyle.secondary,
custom_id="ticket_cfg_log",
)
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_message(
"Selectionnez le canal de logs :",
view=LogChannelSelectView(),
ephemeral=True,
)
class ConfigView(discord.ui.LayoutView): class ConfigView(discord.ui.LayoutView):
def __init__(self): def __init__(self):
super().__init__(timeout=None) super().__init__(timeout=None)
@ -186,55 +61,131 @@ class AddCategoryModal(discord.ui.Modal, title="Ajouter une categorie"):
await interaction.response.send_message(f"Categorie **{cat.name}** ajoutee.", ephemeral=True) await interaction.response.send_message(f"Categorie **{cat.name}** ajoutee.", ephemeral=True)
class StaffRoleSelect(discord.ui.RoleSelect): class ConfigToggleButton(discord.ui.Button):
def __init__(self): def __init__(self, enabled: bool):
super().__init__( super().__init__(
placeholder="Role staff...", label="Desactiver" if enabled else "Activer",
custom_id="ticket_staff_role_select", style=discord.ButtonStyle.danger if enabled else discord.ButtonStyle.success,
min_values=1, custom_id="ticket_cfg_toggle",
max_values=1,
) )
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id) config = storage.get_config(interaction.guild_id)
config.staff_role_id = self.values[0].id config.enabled = not config.enabled
storage.save_config(config) storage.save_config(config)
await interaction.response.edit_message( await interaction.response.edit_message(view=ConfigView())
content=f"Role staff defini : {self.values[0].mention}",
view=None,
class ConfigAddCatButton(discord.ui.Button):
def __init__(self):
super().__init__(label="Ajouter categorie", style=discord.ButtonStyle.primary, custom_id="ticket_cfg_addcat")
async def callback(self, interaction: discord.Interaction):
await interaction.response.send_modal(AddCategoryModal())
class ConfigSetStaffButton(discord.ui.Button):
def __init__(self):
super().__init__(label="Role staff", style=discord.ButtonStyle.secondary, custom_id="ticket_cfg_staff")
async def callback(self, interaction: discord.Interaction):
view = discord.ui.View(timeout=300)
sel = discord.ui.RoleSelect(
placeholder="Role staff...", custom_id="ticket_staff_role_select", min_values=1, max_values=1
) )
async def _cb(interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id)
config.staff_role_id = sel.values[0].id
storage.save_config(config)
await interaction.response.edit_message(content=f"Role staff : {sel.values[0].mention}", view=None)
class StaffRoleSelectView(discord.ui.View): sel.callback = _cb
view.add_item(sel)
await interaction.response.send_message("Selectionnez le role staff :", view=view, ephemeral=True)
class ConfigSetLogButton(discord.ui.Button):
def __init__(self): def __init__(self):
super().__init__(timeout=300) super().__init__(label="Canal logs", style=discord.ButtonStyle.secondary, custom_id="ticket_cfg_log")
self.add_item(StaffRoleSelect())
async def callback(self, interaction: discord.Interaction):
class LogChannelSelect(discord.ui.ChannelSelect): view = discord.ui.View(timeout=300)
def __init__(self): sel = discord.ui.ChannelSelect(
super().__init__(
placeholder="Canal de logs...", placeholder="Canal de logs...",
custom_id="ticket_log_channel_select", custom_id="ticket_log_channel_select",
channel_types=[discord.ChannelType.text, discord.ChannelType.public_thread], channel_types=[discord.ChannelType.text],
min_values=1, min_values=1,
max_values=1, max_values=1,
) )
async def callback(self, interaction: discord.Interaction): async def _cb(interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id)
config.log_channel_id = sel.values[0].id
storage.save_config(config)
await interaction.response.edit_message(content=f"Canal de logs : {sel.values[0].mention}", view=None)
sel.callback = _cb
view.add_item(sel)
await interaction.response.send_message("Selectionnez le canal de logs :", view=view, ephemeral=True)
class TicketSystem(commands.Cog):
ticket = app_commands.Group(name="ticket", description="Systeme de tickets")
def __init__(self, bot: commands.Bot):
self.bot = bot
self.bot.add_view(PanelView())
@commands.Cog.listener()
async def on_ready(self):
logger.info("TicketSystem cog charge")
@ticket.command(name="setup", description="Envoyer le panneau de tickets")
@app_commands.describe(channel="Canal pour le panneau")
@app_commands.checks.has_permissions(manage_guild=True)
async def ticket_setup(self, interaction: discord.Interaction, channel: discord.TextChannel):
config = storage.get_config(interaction.guild_id) config = storage.get_config(interaction.guild_id)
config.log_channel_id = self.values[0].id config.enabled = True
config.panel_channel_id = channel.id
storage.save_config(config) storage.save_config(config)
await interaction.response.edit_message( view = PanelView()
content=f"Canal de logs defini : {self.values[0].mention}", msg = await channel.send(view=view)
view=None, config.panel_message_id = msg.id
storage.save_config(config)
container = discord.ui.Container()
container.add_item(discord.ui.TextDisplay(f"## Panneau envoye\nCanal : {channel.mention}\nStatut : Actif"))
resp_view = discord.ui.LayoutView()
resp_view.add_item(container)
await interaction.response.send_message(view=resp_view, ephemeral=True)
@ticket.command(name="config", description="Configuration du systeme de tickets")
@app_commands.checks.has_permissions(manage_guild=True)
async def ticket_config(self, interaction: discord.Interaction):
config = storage.get_config(interaction.guild_id)
cats = "\n".join(f"- {c.emoji} **{c.name}**" for c in config.categories) or "*Aucune*"
staff_line = f"**Role staff :** <@&{config.staff_role_id}>\n" if config.staff_role_id else ""
log_line = f"**Canal de logs :** <#{config.log_channel_id}>\n" if config.log_channel_id else ""
container = discord.ui.Container()
container.add_item(
discord.ui.TextDisplay(
f"## Configuration Tickets\n"
f"**Statut :** {'Actif' if config.enabled else 'Inactif'}\n"
f"{staff_line}{log_line}### Categories\n{cats}"
)
) )
container.add_item(discord.ui.Separator())
container.add_item(
class LogChannelSelectView(discord.ui.View): discord.ui.ActionRow(
def __init__(self): ConfigToggleButton(config.enabled),
super().__init__(timeout=300) ConfigAddCatButton(),
self.add_item(LogChannelSelect()) ConfigSetStaffButton(),
ConfigSetLogButton(),
)
)
view = discord.ui.LayoutView()
view.add_item(container)
await interaction.response.send_message(view=view, ephemeral=True)
async def setup(bot: commands.Bot): async def setup(bot: commands.Bot):