Initialisation du repository de Beta
This commit is contained in:
commit
14985f6dbb
9469 changed files with 1903273 additions and 0 deletions
78
commandes/security/unban.py
Normal file
78
commandes/security/unban.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import discord
|
||||
|
||||
async def execute(bot, params, message):
|
||||
users = params.get('users', [])
|
||||
if not users:
|
||||
# Fallback for single user
|
||||
users = [params]
|
||||
unbanned_count = 0
|
||||
for user_params in users:
|
||||
target_mention = user_params.get('target_user_mention')
|
||||
user_id = None
|
||||
|
||||
# 1. Try strict ID parsing first
|
||||
try:
|
||||
user_id = int(target_mention)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 2. Try Mention parsing (specific to generic)
|
||||
if user_id is None:
|
||||
if target_mention.startswith('<@!') and target_mention.endswith('>'):
|
||||
try:
|
||||
user_id = int(target_mention[3:-1])
|
||||
except ValueError:
|
||||
pass
|
||||
elif target_mention.startswith('<@') and target_mention.endswith('>'):
|
||||
try:
|
||||
user_id = int(target_mention[2:-1])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
user = None
|
||||
if user_id:
|
||||
try:
|
||||
user = bot.get_user(user_id) or await bot.fetch_user(user_id)
|
||||
except discord.NotFound:
|
||||
pass
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
|
||||
# 3. If no ID match, search by name in ban list
|
||||
if not user:
|
||||
try:
|
||||
# Fetch all bans to search by name
|
||||
bans = [entry async for entry in message.guild.bans()]
|
||||
target_lower = target_mention.lower()
|
||||
target_clean = target_lower[1:] if target_lower.startswith('@') else target_lower
|
||||
|
||||
for ban_entry in bans:
|
||||
u = ban_entry.user
|
||||
# Check: name, global_name, name#discrim
|
||||
u_global = (u.global_name or "").lower()
|
||||
u_name = u.name.lower()
|
||||
|
||||
if (u_name == target_lower or
|
||||
u_name == target_clean or
|
||||
u_global == target_lower or
|
||||
u_global == target_clean or
|
||||
f"{u_name}#{u.discriminator}" == target_lower):
|
||||
user = u
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Error searching bans: {e}")
|
||||
|
||||
if not user:
|
||||
await message.channel.send(f"Utilisateur {target_mention} introuvable (ni ID, ni Mention, ni Nom dans les bannis).")
|
||||
continue
|
||||
|
||||
try:
|
||||
await message.guild.unban(user, reason="Débannissement par le Superviseur")
|
||||
unbanned_count += 1
|
||||
except discord.Forbidden:
|
||||
await message.channel.send(f"Je n'ai pas les permissions pour débannir {user.mention}.")
|
||||
except discord.NotFound:
|
||||
await message.channel.send(f"{user.mention} n'est pas banni.")
|
||||
|
||||
if unbanned_count > 0:
|
||||
await message.channel.send(f"{unbanned_count} utilisateur(s) débanni(s).")
|
||||
Loading…
Add table
Add a link
Reference in a new issue