modified: bot.py
This commit is contained in:
145
bot.py
145
bot.py
@@ -3416,15 +3416,92 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
)
|
)
|
||||||
await send_response(embed=embed)
|
await send_response(embed=embed)
|
||||||
|
|
||||||
@client.hybrid_command()
|
async def get_active_mute_info(user_id, guild_id):
|
||||||
async def mywarns(ctx):
|
"""Gets information about active mute for a user"""
|
||||||
"""Shows your current warning count and moderation statistics"""
|
|
||||||
try:
|
try:
|
||||||
user_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
connection = connect_to_database()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
# Check for active mute process
|
||||||
|
select_query = """
|
||||||
|
SELECT uuid, end_time, data, created_at
|
||||||
|
FROM active_processes
|
||||||
|
WHERE process_type = 'mute'
|
||||||
|
AND status = 'active'
|
||||||
|
AND user_id = %s
|
||||||
|
AND guild_id = %s
|
||||||
|
AND end_time > NOW()
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
cursor.execute(select_query, (user_id, guild_id))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
|
||||||
|
if result:
|
||||||
|
uuid, end_time, data_json, created_at = result
|
||||||
|
data = json.loads(data_json) if data_json else {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"uuid": uuid,
|
||||||
|
"end_time": end_time,
|
||||||
|
"reason": data.get("reason", "No reason provided"),
|
||||||
|
"moderator_id": data.get("moderator_id"),
|
||||||
|
"created_at": created_at
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
close_database_connection(connection)
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error checking active mute: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
@client.hybrid_command()
|
||||||
|
async def account(ctx, user: discord.User = None):
|
||||||
|
"""Shows comprehensive account status including warnings, mutes, and current punishments"""
|
||||||
|
# Check if it's a slash command and defer if needed
|
||||||
|
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.defer()
|
||||||
|
|
||||||
|
# Helper function for sending responses
|
||||||
|
async def send_response(content=None, embed=None, ephemeral=False, file=None):
|
||||||
|
try:
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file)
|
||||||
|
else:
|
||||||
|
await ctx.send(content=content, embed=embed, file=file)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error sending response: {e}")
|
||||||
|
# Fallback to regular send if followup fails
|
||||||
|
try:
|
||||||
|
await ctx.send(content=content, embed=embed, file=file)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Determine target user (self or specified user for moderators)
|
||||||
|
target_user = user if user else ctx.author
|
||||||
|
is_self_check = target_user.id == ctx.author.id
|
||||||
|
|
||||||
|
# If checking another user, verify moderation permissions
|
||||||
|
if not is_self_check:
|
||||||
|
mod_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
||||||
|
if not check_moderation_permission(mod_data["permission"]):
|
||||||
|
embed = discord.Embed(
|
||||||
|
title="❌ Insufficient Permissions",
|
||||||
|
description="You need moderation permissions (Level 5 or higher) to check other users' accounts.",
|
||||||
|
color=0xff0000
|
||||||
|
)
|
||||||
|
await send_response(embed=embed, ephemeral=True)
|
||||||
|
|
||||||
|
user_data = await load_user_data(target_user.id, ctx.guild.id)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="📊 Your Moderation Statistics",
|
title=f"📊 Account Status: {target_user.display_name}",
|
||||||
description=f"Moderation data for {ctx.author.mention}",
|
description=f"Complete account overview for {target_user.mention}",
|
||||||
color=0x3498db,
|
color=0x3498db,
|
||||||
timestamp=datetime.now()
|
timestamp=datetime.now()
|
||||||
)
|
)
|
||||||
@@ -3433,7 +3510,7 @@ async def mywarns(ctx):
|
|||||||
guild_settings = get_guild_settings(ctx.guild.id)
|
guild_settings = get_guild_settings(ctx.guild.id)
|
||||||
|
|
||||||
# Get detailed warning records
|
# Get detailed warning records
|
||||||
warning_records = await get_user_warnings(ctx.author.id, ctx.guild.id)
|
warning_records = await get_user_warnings(target_user.id, ctx.guild.id)
|
||||||
|
|
||||||
# Warning information with threshold
|
# Warning information with threshold
|
||||||
warn_threshold = guild_settings.get("max_warn_threshold", 3)
|
warn_threshold = guild_settings.get("max_warn_threshold", 3)
|
||||||
@@ -3460,9 +3537,20 @@ async def mywarns(ctx):
|
|||||||
inline=True
|
inline=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check for active mute
|
||||||
|
active_mute_info = await get_active_mute_info(target_user.id, ctx.guild.id)
|
||||||
|
if active_mute_info:
|
||||||
|
mute_text = f"🔇 **CURRENTLY MUTED**\n"
|
||||||
|
mute_text += f"Ends: <t:{int(active_mute_info['end_time'].timestamp())}:R>\n"
|
||||||
|
mute_text += f"Reason: {active_mute_info['reason'][:50]}{'...' if len(active_mute_info['reason']) > 50 else ''}"
|
||||||
|
embed.add_field(name="🚨 Active Punishment", value=mute_text, inline=False)
|
||||||
|
|
||||||
# Status assessment
|
# Status assessment
|
||||||
total_infractions = user_data["warns"] + user_data["mutes"] + user_data["ai_ban"]
|
total_infractions = user_data["warns"] + user_data["mutes"] + user_data["ai_ban"]
|
||||||
if total_infractions == 0:
|
if active_mute_info:
|
||||||
|
status = "🔇 **Currently Muted** - Active punishment"
|
||||||
|
status_color = 0xff0000
|
||||||
|
elif total_infractions == 0:
|
||||||
status = "✅ **Clean Record** - No infractions"
|
status = "✅ **Clean Record** - No infractions"
|
||||||
status_color = 0x00ff00
|
status_color = 0x00ff00
|
||||||
elif total_infractions <= 2:
|
elif total_infractions <= 2:
|
||||||
@@ -3475,7 +3563,7 @@ async def mywarns(ctx):
|
|||||||
status = "🔴 **High Risk** - Serious moderation attention"
|
status = "🔴 **High Risk** - Serious moderation attention"
|
||||||
status_color = 0xff0000
|
status_color = 0xff0000
|
||||||
|
|
||||||
embed.add_field(name="📈 Status", value=status, inline=False)
|
embed.add_field(name="📈 Account Status", value=status, inline=False)
|
||||||
embed.color = status_color
|
embed.color = status_color
|
||||||
|
|
||||||
# Detailed warning history (show last 5 warnings)
|
# Detailed warning history (show last 5 warnings)
|
||||||
@@ -3509,6 +3597,24 @@ async def mywarns(ctx):
|
|||||||
|
|
||||||
embed.add_field(name="📋 Warning Details", value=warning_history, inline=False)
|
embed.add_field(name="📋 Warning Details", value=warning_history, inline=False)
|
||||||
|
|
||||||
|
# Account details
|
||||||
|
member = ctx.guild.get_member(target_user.id)
|
||||||
|
if member:
|
||||||
|
account_details = ""
|
||||||
|
account_details += f"**Joined Server:** <t:{int(member.joined_at.timestamp())}:D>\n"
|
||||||
|
account_details += f"**Account Created:** <t:{int(target_user.created_at.timestamp())}:D>\n"
|
||||||
|
account_details += f"**Permission Level:** {user_data['permission']}\n"
|
||||||
|
account_details += f"**XP:** {user_data.get('xp', 0)} (Level {user_data.get('level', 1)})"
|
||||||
|
embed.add_field(name="👤 Account Info", value=account_details, inline=True)
|
||||||
|
|
||||||
|
# Role information
|
||||||
|
if member.roles[1:]: # Exclude @everyone
|
||||||
|
role_list = [role.mention for role in member.roles[1:]][:5] # Show max 5 roles
|
||||||
|
role_text = ", ".join(role_list)
|
||||||
|
if len(member.roles) > 6:
|
||||||
|
role_text += f" +{len(member.roles) - 6} more"
|
||||||
|
embed.add_field(name="🎭 Roles", value=role_text, inline=True)
|
||||||
|
|
||||||
# Get guild settings for thresholds
|
# Get guild settings for thresholds
|
||||||
threshold_info = f"Warning threshold: **{warn_threshold}** warnings"
|
threshold_info = f"Warning threshold: **{warn_threshold}** warnings"
|
||||||
auto_mute_enabled = guild_settings.get("auto_mute_on_warns", False)
|
auto_mute_enabled = guild_settings.get("auto_mute_on_warns", False)
|
||||||
@@ -3518,10 +3624,10 @@ async def mywarns(ctx):
|
|||||||
|
|
||||||
embed.add_field(name="⚙️ Server Settings", value=threshold_info, inline=False)
|
embed.add_field(name="⚙️ Server Settings", value=threshold_info, inline=False)
|
||||||
|
|
||||||
# Tips for improvement
|
# Tips for improvement (only show for users with infractions and when checking self)
|
||||||
if total_infractions > 0:
|
if total_infractions > 0 and is_self_check:
|
||||||
tips = (
|
tips = (
|
||||||
"<EFBFBD> **Tips to improve:**\n"
|
"💡 **Tips to improve:**\n"
|
||||||
"• Follow server rules carefully\n"
|
"• Follow server rules carefully\n"
|
||||||
"• Be respectful to other members\n"
|
"• Be respectful to other members\n"
|
||||||
"• Ask moderators if you're unsure about something\n"
|
"• Ask moderators if you're unsure about something\n"
|
||||||
@@ -3529,14 +3635,19 @@ async def mywarns(ctx):
|
|||||||
)
|
)
|
||||||
embed.add_field(name="Improvement Guide", value=tips, inline=False)
|
embed.add_field(name="Improvement Guide", value=tips, inline=False)
|
||||||
|
|
||||||
embed.set_thumbnail(url=ctx.author.display_avatar.url)
|
embed.set_thumbnail(url=target_user.display_avatar.url)
|
||||||
embed.set_footer(text=f"User ID: {ctx.author.id}")
|
embed.set_footer(text=f"User ID: {target_user.id} | Checked by: {ctx.author.display_name}")
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await send_response(embed=embed)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in mywarns command: {e}")
|
logger.error(f"Error in account command: {e}")
|
||||||
await ctx.send("❌ An error occurred while retrieving your warning information.")
|
await send_response(content="❌ An error occurred while retrieving account information.")
|
||||||
|
|
||||||
|
@client.hybrid_command()
|
||||||
|
async def mywarns(ctx):
|
||||||
|
"""Shows your account status (alias for /account)"""
|
||||||
|
await account(ctx, user=None)
|
||||||
|
|
||||||
@client.hybrid_command()
|
@client.hybrid_command()
|
||||||
async def modinfo(ctx, user: discord.User = None):
|
async def modinfo(ctx, user: discord.User = None):
|
||||||
|
|||||||
Reference in New Issue
Block a user