Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -9,8 +9,14 @@ async def execute(bot, params, message):
created_count = 0
for channel_params in channels:
channel_name = channel_params.get('channel_name')
if not channel_name:
await message.channel.send("Nom de salon requis pour la création.")
continue
category_name = channel_params.get('category_name')
channel_type = channel_params.get('channel_type', 'textuel')
channel_type = (channel_params.get('channel_type') or 'textuel').casefold()
category = None
if category_name:
# Recherche flexible : trouver une catégorie dont le nom contient le terme recherché
category = discord.utils.find(
@ -25,12 +31,11 @@ async def execute(bot, params, message):
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour créer la catégorie '{category_name}'.")
continue
else:
category = None
try:
if channel_type.casefold() == 'textuel':
if channel_type == 'textuel':
channel = await guild.create_text_channel(channel_name, category=category)
elif channel_type.casefold() == 'vocal':
elif channel_type == 'vocal':
channel = await guild.create_voice_channel(channel_name, category=category)
else:
await message.channel.send(f"Type de salon invalide pour '{channel_name}'. Utilisez 'textuel' ou 'vocal'.")
@ -39,4 +44,4 @@ async def execute(bot, params, message):
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour créer le salon '{channel_name}'.")
if created_count > 0:
await message.channel.send(f"{created_count} salon(s) créé(s).")
await message.channel.send(f"{created_count} salon(s) créé(s).")

View file

@ -1,5 +1,40 @@
import discord
async def _find_channel(guild, channel_params):
"""Find a channel by ID first, then by name (case-insensitive)."""
channel_id = channel_params.get('channel_id')
if channel_id:
try:
ch = guild.get_channel(int(channel_id))
if ch:
return ch
except (ValueError, TypeError):
pass
channel_name = channel_params.get('channel_name')
if not channel_name:
return None
return discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
async def _find_category(guild, category_params):
"""Find a category by ID first, then by name (case-insensitive)."""
# Support both 'category_id' and 'new_category_id'
category_id = category_params.get('new_category_id') or category_params.get('category_id')
if category_id:
try:
cat = guild.get_channel(int(category_id))
if cat and isinstance(cat, discord.CategoryChannel):
return cat
except (ValueError, TypeError):
pass
category_name = category_params.get('new_category_name') or category_params.get('category_name')
if not category_name:
return None
return discord.utils.find(lambda cat: cat.name.casefold() == category_name.casefold(), guild.categories)
async def execute(bot, params, message):
channels = params.get('channels', [])
if not channels:
@ -10,18 +45,26 @@ async def execute(bot, params, message):
for channel_params in channels:
channel_name = channel_params.get('channel_name')
new_category_name = channel_params.get('new_category_name')
channel = discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
channel = await _find_channel(guild, channel_params)
if not channel:
await message.channel.send(f"Salon '{channel_name}' introuvable.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Salon '{label}' introuvable.")
continue
category = discord.utils.find(lambda cat: cat.name.casefold() == new_category_name.casefold(), guild.categories)
category = await _find_category(guild, channel_params)
if not category:
await message.channel.send(f"Catégorie '{new_category_name}' introuvable.")
continue
has_category_param = any(k in channel_params for k in ['new_category_id', 'new_category_name', 'category_id', 'category_name'])
if has_category_param:
label = new_category_name or channel_params.get('new_category_id') or channel_params.get('category_id', 'inconnue')
await message.channel.send(f"Catégorie '{label}' introuvable.")
continue
try:
await channel.edit(category=category)
moved_count += 1
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour déplacer le salon '{channel_name}'.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Je n'ai pas les permissions pour déplacer le salon '{label}'.")
if moved_count > 0:
await message.channel.send(f"{moved_count} salon(s) déplacé(s).")
await message.channel.send(f"{moved_count} salon(s) déplacé(s).")

View file

@ -1,5 +1,39 @@
import discord
async def _find_channel(guild, channel_params):
"""Find a channel by ID first, then by name (case-insensitive)."""
channel_id = channel_params.get('channel_id')
if channel_id:
try:
ch = guild.get_channel(int(channel_id))
if ch:
return ch
except (ValueError, TypeError):
pass
channel_name = channel_params.get('channel_name')
if not channel_name:
return None
return discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
async def _find_category(guild, category_params):
"""Find a category by ID first, then by name (case-insensitive)."""
category_id = category_params.get('new_category_id') or category_params.get('category_id')
if category_id:
try:
cat = guild.get_channel(int(category_id))
if cat and isinstance(cat, discord.CategoryChannel):
return cat
except (ValueError, TypeError):
pass
category_name = category_params.get('new_category_name') or category_params.get('category_name')
if not category_name:
return None
return discord.utils.find(lambda cat: cat.name.casefold() == category_name.casefold(), guild.categories)
async def execute(bot, params, message):
channels = params.get('channels', [])
if not channels:
@ -9,15 +43,43 @@ async def execute(bot, params, message):
modified_count = 0
for channel_params in channels:
channel_name = channel_params.get('channel_name')
new_name = channel_params.get('new_name')
channel = discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
# Support both 'new_name' and 'new_channel_name' variants
new_name = channel_params.get('new_name') or channel_params.get('new_channel_name')
new_category_id = channel_params.get('new_category_id')
new_category_name = channel_params.get('new_category_name')
channel = await _find_channel(guild, channel_params)
if not channel:
await message.channel.send(f"Salon '{channel_name}' introuvable.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Salon '{label}' introuvable.")
continue
# Build edit kwargs based on what params are provided
edit_kwargs = {}
if new_name:
edit_kwargs['name'] = new_name
if new_category_id or new_category_name:
category = await _find_category(guild, channel_params)
if category:
edit_kwargs['category'] = category
else:
cat_label = new_category_name or new_category_id or 'inconnue'
await message.channel.send(f"Catégorie '{cat_label}' introuvable.")
continue
if not edit_kwargs:
await message.channel.send("Aucune modification à appliquer (ni nom, ni catégorie spécifiés).")
continue
try:
await channel.edit(name=new_name)
await channel.edit(**edit_kwargs)
modified_count += 1
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour modifier le salon '{channel_name}'.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Je n'ai pas les permissions pour modifier le salon '{label}'.")
except Exception as e:
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Erreur lors de la modification du salon '{label}': {e}")
if modified_count > 0:
await message.channel.send(f"{modified_count} salon(s) modifié(s).")
await message.channel.send(f"{modified_count} salon(s) modifié(s).")

View file

@ -1,5 +1,22 @@
import discord
async def _find_channel(guild, channel_params):
"""Find a channel by ID first, then by name (case-insensitive)."""
channel_id = channel_params.get('channel_id')
if channel_id:
try:
ch = guild.get_channel(int(channel_id))
if ch:
return ch
except (ValueError, TypeError):
pass
channel_name = channel_params.get('channel_name')
if not channel_name:
return None
return discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
async def execute(bot, params, message):
channels = params.get('channels', [])
if not channels:
@ -9,15 +26,27 @@ async def execute(bot, params, message):
renamed_count = 0
for channel_params in channels:
channel_name = channel_params.get('channel_name')
new_name = channel_params.get('new_name')
channel = discord.utils.find(lambda c: c.name.casefold() == channel_name.casefold(), guild.channels)
# Support both 'new_name' and 'new_channel_name' variants
new_name = channel_params.get('new_name') or channel_params.get('new_channel_name')
channel = await _find_channel(guild, channel_params)
if not channel:
await message.channel.send(f"Salon '{channel_name}' introuvable.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Salon '{label}' introuvable.")
continue
if not new_name:
await message.channel.send("Aucun nouveau nom spécifié pour le renommage.")
continue
try:
await channel.edit(name=new_name)
renamed_count += 1
except discord.Forbidden:
await message.channel.send(f"Je n'ai pas les permissions pour renommer le salon '{channel_name}'.")
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Je n'ai pas les permissions pour renommer le salon '{label}'.")
except Exception as e:
label = channel_name or channel_params.get('channel_id', 'inconnu')
await message.channel.send(f"Erreur lors du renommage du salon '{label}': {e}")
if renamed_count > 0:
await message.channel.send(f"{renamed_count} salon(s) renommé(s).")
await message.channel.send(f"{renamed_count} salon(s) renommé(s).")