45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
|
import discord
|
||
|
|
from discord import app_commands
|
||
|
|
from discord.ext import commands
|
||
|
|
import re
|
||
|
|
|
||
|
|
class FormatAllNicknames(commands.Cog):
|
||
|
|
def __init__(self, bot):
|
||
|
|
self.bot = bot
|
||
|
|
|
||
|
|
@app_commands.command(name="formatall", description="Force tous les pseudos au format 'Prénom Nom | Epic'")
|
||
|
|
@app_commands.checks.has_permissions(manage_nicknames=True)
|
||
|
|
async def format_all(self, interaction: discord.Interaction):
|
||
|
|
await interaction.response.defer(thinking=True)
|
||
|
|
guild = interaction.guild
|
||
|
|
modified_count = 0
|
||
|
|
|
||
|
|
# Regex : deux mots avant le "|"
|
||
|
|
pattern_correct = re.compile(r"^[^\|]+\s[^\|]+\s\| .+")
|
||
|
|
|
||
|
|
for member in guild.members:
|
||
|
|
if member.bot:
|
||
|
|
continue
|
||
|
|
|
||
|
|
current_nick = member.nick or member.name
|
||
|
|
|
||
|
|
# S'il respecte déjà le bon format ("Prénom Nom | Quelquechose"), on skip
|
||
|
|
if pattern_correct.match(current_nick):
|
||
|
|
continue
|
||
|
|
|
||
|
|
try:
|
||
|
|
# Sinon, forcer à "Prénom Nom | Epic"
|
||
|
|
new_nick = "Prénom Nom | Epic"
|
||
|
|
|
||
|
|
await member.edit(nick=new_nick)
|
||
|
|
modified_count += 1
|
||
|
|
|
||
|
|
except discord.Forbidden:
|
||
|
|
continue
|
||
|
|
except discord.HTTPException:
|
||
|
|
continue
|
||
|
|
|
||
|
|
await interaction.followup.send(f"✅ Renommage terminé : {modified_count} membres modifiés.")
|
||
|
|
|
||
|
|
async def setup(bot):
|
||
|
|
await bot.add_cog(FormatAllNicknames(bot))
|