modified: bot.py
This commit is contained in:
54
bot.py
54
bot.py
@@ -1991,7 +1991,7 @@ async def modhelp(ctx):
|
|||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="👮 Moderator Commands (Level 5+)",
|
name="👮 Moderator Commands (Level 5+)",
|
||||||
value=(
|
value=(
|
||||||
"`/warn <user> [reason | message_id]` - Warn a user (with optional message reference)\n"
|
"`/warn <user> [reason] [message_id]` - Warn a user (with optional message reference)\n"
|
||||||
"`/mute <user> <duration> [reason]` - Mute a user temporarily\n"
|
"`/mute <user> <duration> [reason]` - Mute a user temporarily\n"
|
||||||
"`/unmute <user>` - Manually unmute a user\n"
|
"`/unmute <user>` - Manually unmute a user\n"
|
||||||
"`/modinfo [user]` - View comprehensive user information\n"
|
"`/modinfo [user]` - View comprehensive user information\n"
|
||||||
@@ -2053,6 +2053,7 @@ async def modhelp(ctx):
|
|||||||
"`10m` = 10 minutes, `1h` = 1 hour, `2d` = 2 days\n\n"
|
"`10m` = 10 minutes, `1h` = 1 hour, `2d` = 2 days\n\n"
|
||||||
"**Warning with message reference:**\n"
|
"**Warning with message reference:**\n"
|
||||||
"`/warn @user Inappropriate behavior | 1234567890123456789`\n"
|
"`/warn @user Inappropriate behavior | 1234567890123456789`\n"
|
||||||
|
"`/warn @user Bad language 1234567890123456789`\n"
|
||||||
"The message will be saved even if deleted later."
|
"The message will be saved even if deleted later."
|
||||||
),
|
),
|
||||||
inline=False
|
inline=False
|
||||||
@@ -2943,19 +2944,41 @@ async def warn(ctx, user: discord.User, *, reason_and_message: str = "No reason
|
|||||||
Usage:
|
Usage:
|
||||||
/warn @user Inappropriate behavior
|
/warn @user Inappropriate behavior
|
||||||
/warn @user Spam messages | 1234567890123456789
|
/warn @user Spam messages | 1234567890123456789
|
||||||
|
/warn @user Bad behavior 1234567890123456789
|
||||||
|
|
||||||
Format: reason | message_id (optional)
|
Format: reason | message_id OR reason message_id (message_id optional)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Parse reason and optional message ID
|
# Parse reason and optional message ID - support multiple formats
|
||||||
reason_parts = reason_and_message.split(" | ")
|
reason = reason_and_message.strip()
|
||||||
reason = reason_parts[0].strip()
|
|
||||||
message_id = None
|
message_id = None
|
||||||
message_data = None
|
message_data = None
|
||||||
|
|
||||||
|
# Method 1: Check for " | " separator
|
||||||
|
if " | " in reason_and_message:
|
||||||
|
reason_parts = reason_and_message.split(" | ")
|
||||||
|
reason = reason_parts[0].strip()
|
||||||
if len(reason_parts) > 1:
|
if len(reason_parts) > 1:
|
||||||
try:
|
try:
|
||||||
message_id = int(reason_parts[1].strip())
|
message_id = int(reason_parts[1].strip())
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# Method 2: Check if last word is a valid message ID (18-19 digits)
|
||||||
|
words = reason_and_message.strip().split()
|
||||||
|
if len(words) > 1:
|
||||||
|
last_word = words[-1]
|
||||||
|
# Discord message IDs are 18-19 digits long
|
||||||
|
if last_word.isdigit() and 17 <= len(last_word) <= 20:
|
||||||
|
try:
|
||||||
|
message_id = int(last_word)
|
||||||
|
# Remove the message ID from reason
|
||||||
|
reason = " ".join(words[:-1]).strip()
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Try to get message data if message ID was found
|
||||||
|
if message_id:
|
||||||
# Try to get message data from current channel first
|
# Try to get message data from current channel first
|
||||||
message_data = await get_message_data(ctx.channel, message_id)
|
message_data = await get_message_data(ctx.channel, message_id)
|
||||||
|
|
||||||
@@ -2969,13 +2992,26 @@ async def warn(ctx, user: discord.User, *, reason_and_message: str = "No reason
|
|||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
except ValueError:
|
|
||||||
await ctx.send("❌ Invalid message ID format. Use: `/warn @user reason | 1234567890123456789`", ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Load moderator data
|
# Load moderator data
|
||||||
mod_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
mod_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
||||||
|
|
||||||
|
# Debug: Show parsed information (for testing)
|
||||||
|
debug_info = f"**Parsed Information:**\n"
|
||||||
|
debug_info += f"Reason: `{reason}`\n"
|
||||||
|
if message_id:
|
||||||
|
debug_info += f"Message ID: `{message_id}`\n"
|
||||||
|
debug_info += f"Message Found: {'✅' if message_data else '❌'}"
|
||||||
|
else:
|
||||||
|
debug_info += "No Message ID provided"
|
||||||
|
|
||||||
|
# Send debug info as ephemeral message
|
||||||
|
debug_embed = discord.Embed(
|
||||||
|
title="🔍 Debug Information",
|
||||||
|
description=debug_info,
|
||||||
|
color=0x3498db
|
||||||
|
)
|
||||||
|
await ctx.send(embed=debug_embed, ephemeral=True)
|
||||||
|
|
||||||
# Check moderation rights
|
# Check moderation rights
|
||||||
if not check_moderation_permission(mod_data["permission"]):
|
if not check_moderation_permission(mod_data["permission"]):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
|
|||||||
Reference in New Issue
Block a user