modified: bot.py
This commit is contained in:
58
bot.py
58
bot.py
@@ -4625,8 +4625,12 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
await send_response(embed=embed)
|
await send_response(embed=embed)
|
||||||
|
|
||||||
@client.hybrid_command()
|
@client.hybrid_command()
|
||||||
async def viewmute(ctx, process_uuid: str):
|
async def viewmute(ctx, identifier: str):
|
||||||
"""View detailed information about a specific mute (Requires Permission Level 5 or higher)"""
|
"""View detailed information about a specific mute (Requires Permission Level 5 or higher)
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- identifier: Mute ID (e.g. 123) or Process UUID (e.g. abc123def-456...)
|
||||||
|
"""
|
||||||
# Check if it's a slash command and defer if needed
|
# Check if it's a slash command and defer if needed
|
||||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||||
if is_slash_command:
|
if is_slash_command:
|
||||||
@@ -4669,6 +4673,9 @@ async def viewmute(ctx, process_uuid: str):
|
|||||||
await send_response(embed=embed, ephemeral=True)
|
await send_response(embed=embed, ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Determine if identifier is a mute ID (numeric) or process UUID (alphanumeric)
|
||||||
|
is_mute_id = identifier.isdigit()
|
||||||
|
|
||||||
# Get mute details from user_mutes database (preferred) or active_processes as fallback
|
# Get mute details from user_mutes database (preferred) or active_processes as fallback
|
||||||
connection = None
|
connection = None
|
||||||
cursor = None
|
cursor = None
|
||||||
@@ -4676,15 +4683,25 @@ async def viewmute(ctx, process_uuid: str):
|
|||||||
connection = connect_to_database()
|
connection = connect_to_database()
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
# First try to find mute in user_mutes table by process_uuid
|
# Try to find mute in user_mutes table
|
||||||
|
if is_mute_id:
|
||||||
|
# Search by mute ID
|
||||||
|
select_query = """
|
||||||
|
SELECT * FROM user_mutes
|
||||||
|
WHERE id = %s AND guild_id = %s
|
||||||
|
LIMIT 1
|
||||||
|
"""
|
||||||
|
cursor.execute(select_query, (int(identifier), ctx.guild.id))
|
||||||
|
else:
|
||||||
|
# Search by process UUID
|
||||||
select_query = """
|
select_query = """
|
||||||
SELECT * FROM user_mutes
|
SELECT * FROM user_mutes
|
||||||
WHERE process_uuid = %s AND guild_id = %s
|
WHERE process_uuid = %s AND guild_id = %s
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
"""
|
"""
|
||||||
|
cursor.execute(select_query, (identifier, ctx.guild.id))
|
||||||
|
|
||||||
cursor.execute(select_query, (process_uuid, ctx.guild.id))
|
|
||||||
mute_result = cursor.fetchone()
|
mute_result = cursor.fetchone()
|
||||||
|
|
||||||
if mute_result:
|
if mute_result:
|
||||||
@@ -4755,7 +4772,7 @@ async def viewmute(ctx, process_uuid: str):
|
|||||||
content_preview = mute_data['message_content'][:100] + "..." if len(mute_data['message_content']) > 100 else mute_data['message_content']
|
content_preview = mute_data['message_content'][:100] + "..." if len(mute_data['message_content']) > 100 else mute_data['message_content']
|
||||||
embed.add_field(name="📄 Referenced Message", value=f"ID: `{mute_data['message_id']}`\nContent: {content_preview}", inline=False)
|
embed.add_field(name="📄 Referenced Message", value=f"ID: `{mute_data['message_id']}`\nContent: {content_preview}", inline=False)
|
||||||
|
|
||||||
embed.add_field(name="🆔 Process UUID", value=f"`{process_uuid}`", inline=False)
|
embed.add_field(name="🆔 Process UUID", value=f"`{mute_data['process_uuid']}`", inline=False)
|
||||||
embed.add_field(name="🆔 Mute Record ID", value=f"`{mute_data['id']}`", inline=True)
|
embed.add_field(name="🆔 Mute Record ID", value=f"`{mute_data['id']}`", inline=True)
|
||||||
|
|
||||||
embed.set_thumbnail(url=muted_user.display_avatar.url)
|
embed.set_thumbnail(url=muted_user.display_avatar.url)
|
||||||
@@ -4765,7 +4782,8 @@ async def viewmute(ctx, process_uuid: str):
|
|||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Fallback to active_processes table
|
# Fallback to active_processes table (only if identifier is UUID format)
|
||||||
|
if not is_mute_id:
|
||||||
select_query = """
|
select_query = """
|
||||||
SELECT uuid, process_type, guild_id, channel_id, user_id, target_id,
|
SELECT uuid, process_type, guild_id, channel_id, user_id, target_id,
|
||||||
created_at, end_time, status, data
|
created_at, end_time, status, data
|
||||||
@@ -4773,13 +4791,18 @@ async def viewmute(ctx, process_uuid: str):
|
|||||||
WHERE uuid = %s AND guild_id = %s AND process_type = 'mute'
|
WHERE uuid = %s AND guild_id = %s AND process_type = 'mute'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cursor.execute(select_query, (process_uuid, ctx.guild.id))
|
cursor.execute(select_query, (identifier, ctx.guild.id))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
if not result:
|
if result:
|
||||||
|
# Process old format result...
|
||||||
|
# [Continue with existing fallback logic]
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If no results found
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="❌ Mute Not Found",
|
title="❌ Mute Not Found",
|
||||||
description=f"No mute with UUID `{process_uuid}` found in this server.",
|
description=f"No mute with {'ID' if is_mute_id else 'UUID'} `{identifier}` found in this server.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await send_response(embed=embed, ephemeral=True)
|
await send_response(embed=embed, ephemeral=True)
|
||||||
@@ -5417,6 +5440,13 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
|
|||||||
}
|
}
|
||||||
|
|
||||||
if message_data:
|
if message_data:
|
||||||
|
# Handle new context message format
|
||||||
|
if isinstance(message_data, dict) and "main_message" in message_data:
|
||||||
|
main_msg = message_data.get("main_message")
|
||||||
|
if main_msg:
|
||||||
|
log_additional_info["Referenced Message"] = f"ID: {main_msg['id']} in <#{main_msg['channel_id']}>"
|
||||||
|
else:
|
||||||
|
# Handle old format
|
||||||
log_additional_info["Referenced Message"] = f"ID: {message_data['id']} in <#{message_data['channel_id']}>"
|
log_additional_info["Referenced Message"] = f"ID: {message_data['id']} in <#{message_data['channel_id']}>"
|
||||||
|
|
||||||
await log_moderation_action(
|
await log_moderation_action(
|
||||||
@@ -5597,7 +5627,7 @@ async def listmutes(ctx, status: str = "active"):
|
|||||||
|
|
||||||
if status.lower() == "all":
|
if status.lower() == "all":
|
||||||
select_query = """
|
select_query = """
|
||||||
SELECT process_uuid, user_id, created_at, end_time, status, reason,
|
SELECT id, process_uuid, user_id, created_at, end_time, status, reason,
|
||||||
duration, aktiv, moderator_id, auto_unmuted, unmuted_at
|
duration, aktiv, moderator_id, auto_unmuted, unmuted_at
|
||||||
FROM user_mutes
|
FROM user_mutes
|
||||||
WHERE guild_id = %s
|
WHERE guild_id = %s
|
||||||
@@ -5617,7 +5647,7 @@ async def listmutes(ctx, status: str = "active"):
|
|||||||
where_condition = "status = 'cancelled'"
|
where_condition = "status = 'cancelled'"
|
||||||
|
|
||||||
select_query = f"""
|
select_query = f"""
|
||||||
SELECT process_uuid, user_id, created_at, end_time, status, reason,
|
SELECT id, process_uuid, user_id, created_at, end_time, status, reason,
|
||||||
duration, aktiv, moderator_id, auto_unmuted, unmuted_at
|
duration, aktiv, moderator_id, auto_unmuted, unmuted_at
|
||||||
FROM user_mutes
|
FROM user_mutes
|
||||||
WHERE guild_id = %s AND ({where_condition})
|
WHERE guild_id = %s AND ({where_condition})
|
||||||
@@ -5647,7 +5677,7 @@ async def listmutes(ctx, status: str = "active"):
|
|||||||
|
|
||||||
mute_list = []
|
mute_list = []
|
||||||
for result in results[:15]: # Limit to 15 to avoid embed limits
|
for result in results[:15]: # Limit to 15 to avoid embed limits
|
||||||
process_uuid, user_id, created_at, end_time, mute_status, reason, duration, aktiv, moderator_id, auto_unmuted, unmuted_at = result
|
mute_id, process_uuid, user_id, created_at, end_time, mute_status, reason, duration, aktiv, moderator_id, auto_unmuted, unmuted_at = result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get user
|
# Get user
|
||||||
@@ -5682,7 +5712,7 @@ async def listmutes(ctx, status: str = "active"):
|
|||||||
else:
|
else:
|
||||||
time_info = f"<t:{int(created_at.timestamp())}:d>"
|
time_info = f"<t:{int(created_at.timestamp())}:d>"
|
||||||
|
|
||||||
mute_entry = f"{status_emoji} **{user_display}** - {reason_display}\n`{process_uuid[:8]}` • {duration} • {time_info}"
|
mute_entry = f"{status_emoji} **{user_display}** - {reason_display}\n`ID: {mute_id}` • {duration} • {time_info}"
|
||||||
mute_list.append(mute_entry)
|
mute_list.append(mute_entry)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -5693,7 +5723,7 @@ async def listmutes(ctx, status: str = "active"):
|
|||||||
mute_text = "\n\n".join(mute_list)
|
mute_text = "\n\n".join(mute_list)
|
||||||
embed.add_field(name="📋 Mutes", value=mute_text, inline=False)
|
embed.add_field(name="📋 Mutes", value=mute_text, inline=False)
|
||||||
|
|
||||||
embed.set_footer(text=f"Use /viewmute <uuid> for detailed info • Showing max 15 results")
|
embed.set_footer(text=f"Use /viewmute <id> for detailed info • Showing max 15 results")
|
||||||
|
|
||||||
await send_response(embed=embed)
|
await send_response(embed=embed)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user