from __future__ import annotations import logging import discord from discord import app_commands from discord.ext import commands from features import shared logger = logging.getLogger("vision") STAFF_RANKS = ["Membre", "Trial", "Modérateur", "Super Modérateur", "Admin", "Fondateur"] class Staff(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @app_commands.command(name="staff_setup", description="Configurer le système de staff") @app_commands.describe(staff_role="Rôle principal du staff") @app_commands.checks.has_permissions(manage_guild=True) async def staff_setup(self, interaction: discord.Interaction, staff_role: discord.Role): cfg = shared.get(interaction.guild_id, "staff") cfg["enabled"] = True cfg["staff_role_id"] = staff_role.id cfg["ranks"] = { "Membre": None, "Trial": None, "Modérateur": None, "Super Modérateur": None, "Admin": None, "Fondateur": None, } shared.set(interaction.guild_id, "staff", cfg) await interaction.response.send_message( f"Système de staff configuré. Rôle principal : {staff_role.mention}", ephemeral=True ) @app_commands.command(name="staff_promote", description="Promouvoir un membre du staff") @app_commands.describe(member="Membre", rank="Rang") @app_commands.checks.has_permissions(manage_roles=True) async def staff_promote(self, interaction: discord.Interaction, member: discord.Member, rank: str): cfg = shared.section(interaction.guild_id, "staff") ranks = cfg.get("ranks", {}) if rank not in ranks: await interaction.response.send_message(f"Rang inconnu. Rangs : {', '.join(STAFF_RANKS)}", ephemeral=True) return if rank not in [r for r in STAFF_RANKS]: await interaction.response.send_message("Rang invalide.", ephemeral=True) return staff = cfg.get("staff", []) entry = next((s for s in staff if s["user_id"] == member.id), None) if entry: entry["rank"] = rank else: staff.append({"user_id": member.id, "username": str(member), "rank": rank}) cfg["staff"] = staff shared.set(interaction.guild_id, "staff", cfg) await interaction.response.send_message(f"**{member}** est maintenant **{rank}**.", ephemeral=True) @app_commands.command(name="staff_demote", description="Rétrograder un membre du staff") @app_commands.describe(member="Membre") @app_commands.checks.has_permissions(manage_roles=True) async def staff_demote(self, interaction: discord.Interaction, member: discord.Member): cfg = shared.get(interaction.guild_id, "staff") staff = cfg.get("staff", []) idx = next((i for i, s in enumerate(staff) if s["user_id"] == member.id), None) if idx is None: await interaction.response.send_message(f"**{member}** n'est pas dans le staff.", ephemeral=True) return current = staff[idx]["rank"] rank_idx = STAFF_RANKS.index(current) if current in STAFF_RANKS else 0 new_rank = STAFF_RANKS[rank_idx - 1] if rank_idx > 0 else "Membre" staff[idx]["rank"] = new_rank cfg["staff"] = staff shared.set(interaction.guild_id, "staff", cfg) await interaction.response.send_message(f"**{member}** est maintenant **{new_rank}**.", ephemeral=True) @app_commands.command(name="staff_list", description="Voir la liste du staff") async def staff_list(self, interaction: discord.Interaction): cfg = shared.section(interaction.guild_id, "staff") staff = cfg.get("staff", []) if not staff: await interaction.response.send_message("Aucun membre du staff.", ephemeral=True) return lines = [] for s in sorted( staff, key=lambda x: STAFF_RANKS.index(x["rank"]) if x["rank"] in STAFF_RANKS else 0, reverse=True ): lines.append(f"**{s['rank']}** — <@{s['user_id']}>") embed = discord.Embed( title="Équipe Staff", description="\n".join(lines), color=discord.Color.blurple(), ) await interaction.response.send_message(embed=embed) async def setup(bot: commands.Bot): await bot.add_cog(Staff(bot))