modified: bot.py
This commit is contained in:
98
bot.py
98
bot.py
@@ -4625,8 +4625,12 @@ async def viewwarn(ctx, warning_id: int):
|
||||
await send_response(embed=embed)
|
||||
|
||||
@client.hybrid_command()
|
||||
async def viewmute(ctx, process_uuid: str):
|
||||
"""View detailed information about a specific mute (Requires Permission Level 5 or higher)"""
|
||||
async def viewmute(ctx, identifier: str):
|
||||
"""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
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if is_slash_command:
|
||||
@@ -4669,6 +4673,9 @@ async def viewmute(ctx, process_uuid: str):
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
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
|
||||
connection = None
|
||||
cursor = None
|
||||
@@ -4676,15 +4683,25 @@ async def viewmute(ctx, process_uuid: str):
|
||||
connection = connect_to_database()
|
||||
cursor = connection.cursor()
|
||||
|
||||
# First try to find mute in user_mutes table by process_uuid
|
||||
select_query = """
|
||||
SELECT * FROM user_mutes
|
||||
WHERE process_uuid = %s AND guild_id = %s
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
# 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 * FROM user_mutes
|
||||
WHERE process_uuid = %s AND guild_id = %s
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
cursor.execute(select_query, (identifier, ctx.guild.id))
|
||||
|
||||
cursor.execute(select_query, (process_uuid, ctx.guild.id))
|
||||
mute_result = cursor.fetchone()
|
||||
|
||||
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']
|
||||
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.set_thumbnail(url=muted_user.display_avatar.url)
|
||||
@@ -4765,25 +4782,31 @@ async def viewmute(ctx, process_uuid: str):
|
||||
return
|
||||
|
||||
else:
|
||||
# Fallback to active_processes table
|
||||
select_query = """
|
||||
SELECT uuid, process_type, guild_id, channel_id, user_id, target_id,
|
||||
created_at, end_time, status, data
|
||||
FROM active_processes
|
||||
WHERE uuid = %s AND guild_id = %s AND process_type = 'mute'
|
||||
"""
|
||||
# Fallback to active_processes table (only if identifier is UUID format)
|
||||
if not is_mute_id:
|
||||
select_query = """
|
||||
SELECT uuid, process_type, guild_id, channel_id, user_id, target_id,
|
||||
created_at, end_time, status, data
|
||||
FROM active_processes
|
||||
WHERE uuid = %s AND guild_id = %s AND process_type = 'mute'
|
||||
"""
|
||||
|
||||
cursor.execute(select_query, (process_uuid, ctx.guild.id))
|
||||
result = cursor.fetchone()
|
||||
cursor.execute(select_query, (identifier, ctx.guild.id))
|
||||
result = cursor.fetchone()
|
||||
|
||||
if not result:
|
||||
embed = discord.Embed(
|
||||
title="❌ Mute Not Found",
|
||||
description=f"No mute with UUID `{process_uuid}` found in this server.",
|
||||
color=0xff0000
|
||||
)
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
return
|
||||
if result:
|
||||
# Process old format result...
|
||||
# [Continue with existing fallback logic]
|
||||
pass
|
||||
|
||||
# If no results found
|
||||
embed = discord.Embed(
|
||||
title="❌ Mute Not Found",
|
||||
description=f"No mute with {'ID' if is_mute_id else 'UUID'} `{identifier}` found in this server.",
|
||||
color=0xff0000
|
||||
)
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
return
|
||||
|
||||
# Parse result (fallback to old format)
|
||||
uuid, process_type, guild_id, channel_id, user_id, target_id, created_at, end_time, status, data = result
|
||||
@@ -5417,7 +5440,14 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
|
||||
}
|
||||
|
||||
if message_data:
|
||||
log_additional_info["Referenced Message"] = f"ID: {message_data['id']} in <#{message_data['channel_id']}>"
|
||||
# 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']}>"
|
||||
|
||||
await log_moderation_action(
|
||||
guild=ctx.guild,
|
||||
@@ -5597,7 +5627,7 @@ async def listmutes(ctx, status: str = "active"):
|
||||
|
||||
if status.lower() == "all":
|
||||
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
|
||||
FROM user_mutes
|
||||
WHERE guild_id = %s
|
||||
@@ -5617,7 +5647,7 @@ async def listmutes(ctx, status: str = "active"):
|
||||
where_condition = "status = 'cancelled'"
|
||||
|
||||
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
|
||||
FROM user_mutes
|
||||
WHERE guild_id = %s AND ({where_condition})
|
||||
@@ -5647,7 +5677,7 @@ async def listmutes(ctx, status: str = "active"):
|
||||
|
||||
mute_list = []
|
||||
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:
|
||||
# Get user
|
||||
@@ -5682,7 +5712,7 @@ async def listmutes(ctx, status: str = "active"):
|
||||
else:
|
||||
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)
|
||||
|
||||
except Exception as e:
|
||||
@@ -5693,7 +5723,7 @@ async def listmutes(ctx, status: str = "active"):
|
||||
mute_text = "\n\n".join(mute_list)
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user