modified: bot.py
modified: bot.py
This commit is contained in:
25
bot.py
25
bot.py
@@ -2640,7 +2640,7 @@ async def log_moderation_action(guild, action_type, moderator, target_user, reas
|
||||
except Exception as e:
|
||||
logger.error(f"Error logging moderation action: {e}")
|
||||
|
||||
async def save_warning_to_database(user_id, guild_id, moderator_id, reason, timestamp=None, message_data=None):
|
||||
async def save_warning_to_database(user_id, guild_id, moderator_id, reason, timestamp=None, message_data=None, message_id=None):
|
||||
"""Saves individual warning records to the database with optional message data"""
|
||||
connection = None
|
||||
cursor = None
|
||||
@@ -2652,14 +2652,14 @@ async def save_warning_to_database(user_id, guild_id, moderator_id, reason, time
|
||||
timestamp = datetime.now()
|
||||
|
||||
# Prepare message data if provided
|
||||
message_id = None
|
||||
message_id_db = message_id # Use provided message_id
|
||||
message_content = None
|
||||
message_attachments = None
|
||||
message_author_id = None
|
||||
message_channel_id = None
|
||||
|
||||
if message_data:
|
||||
message_id = message_data.get('id')
|
||||
message_id_db = message_data.get('id')
|
||||
message_content = message_data.get('content')
|
||||
message_attachments = message_data.get('attachments') # JSON string
|
||||
message_author_id = message_data.get('author_id')
|
||||
@@ -2673,7 +2673,7 @@ async def save_warning_to_database(user_id, guild_id, moderator_id, reason, time
|
||||
"""
|
||||
|
||||
cursor.execute(insert_query, (
|
||||
user_id, guild_id, moderator_id, reason, message_id,
|
||||
user_id, guild_id, moderator_id, reason, message_id_db,
|
||||
message_content, message_attachments, message_author_id,
|
||||
message_channel_id, timestamp
|
||||
))
|
||||
@@ -2937,12 +2937,12 @@ async def restore_user_roles(user, guild):
|
||||
close_database_connection(connection)
|
||||
|
||||
@client.hybrid_command()
|
||||
async def warn(ctx, user: discord.User, reason: str = "No reason provided", message_id: int = None):
|
||||
async def warn(ctx, user: discord.User, reason: str = "No reason provided", message_id: str = None):
|
||||
"""Warns a user (Requires Permission Level 5 or higher)
|
||||
|
||||
Usage:
|
||||
/warn @user "Inappropriate behavior"
|
||||
/warn @user "Bad language" 1234567890123456789
|
||||
/warn @user "Bad language" 1407754702564884622
|
||||
|
||||
Parameters:
|
||||
- user: The user to warn
|
||||
@@ -2955,14 +2955,20 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
|
||||
# Try to get message data if message ID was provided
|
||||
if message_id:
|
||||
# Convert message_id string to int
|
||||
try:
|
||||
message_id_int = int(message_id)
|
||||
except ValueError:
|
||||
await ctx.send(f"❌ Invalid message ID: {message_id}")
|
||||
return
|
||||
# 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_int)
|
||||
|
||||
# If not found in current channel, try other channels the bot can access
|
||||
if message_data is None:
|
||||
for channel in ctx.guild.text_channels:
|
||||
try:
|
||||
message_data = await get_message_data(channel, message_id)
|
||||
message_data = await get_message_data(channel, message_id_int)
|
||||
if message_data is not None:
|
||||
break
|
||||
except discord.Forbidden:
|
||||
@@ -3013,7 +3019,8 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
guild_id=ctx.guild.id,
|
||||
moderator_id=ctx.author.id,
|
||||
reason=reason,
|
||||
message_data=message_data
|
||||
message_data=message_data,
|
||||
message_id=message_id_int if message_id else None
|
||||
)
|
||||
|
||||
# Get guild settings for threshold checking
|
||||
|
||||
Reference in New Issue
Block a user