Refactor leaderboard display in Leaderboard cog to enhance user experience. Remove warning message, update embed formatting with server icons, and include percentage rankings. Modernize user stats presentation and improve footer details for clarity.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
This commit is contained in:
parent
2e402ff7cf
commit
d638772e80
1 changed files with 52 additions and 19 deletions
|
@ -358,17 +358,17 @@ class Leaderboard(commands.Cog):
|
|||
if not chunks:
|
||||
return await ctx.send("No users have 10,000 or more credits!")
|
||||
|
||||
# Send warning message first
|
||||
await ctx.send("⚠️ **Note:** The global leaderboard may be slightly inaccurate due to synchronization delays.")
|
||||
|
||||
embeds = []
|
||||
for page_num, entries in enumerate(chunks, 1):
|
||||
embed = discord.Embed(
|
||||
title="🏆 Global Credits Leaderboard",
|
||||
description="*Only showing users with 10,000+ credits*",
|
||||
title="Global Credits Leaderboard",
|
||||
color=await ctx.embed_color()
|
||||
)
|
||||
|
||||
# Add server icon if available
|
||||
if ctx.guild.icon:
|
||||
embed.set_thumbnail(url=ctx.guild.icon.url)
|
||||
|
||||
description = []
|
||||
start_pos = (page_num - 1) * items_per_page
|
||||
|
||||
|
@ -377,12 +377,26 @@ class Leaderboard(commands.Cog):
|
|||
user_id = entry.get("userId", "0")
|
||||
credits = entry.get("points", 0)
|
||||
|
||||
# Calculate percentage position
|
||||
percentage = (i / len(leaderboard_data)) * 100
|
||||
|
||||
# Medal emojis for top 3
|
||||
medal = "🥇" if i == 1 else "🥈" if i == 2 else "🥉" if i == 3 else "•"
|
||||
|
||||
description.append(
|
||||
f"`{i}.` <@{user_id}> • **{humanize_number(credits)}** credits"
|
||||
f"`{i}.` {medal} <@{user_id}>\n"
|
||||
f"┗ 💰 **{humanize_number(credits)}** credits • Top **{percentage:.1f}%**"
|
||||
)
|
||||
|
||||
embed.description = embed.description + "\n\n" + "\n".join(description)
|
||||
embed.set_footer(text=f"Page {page_num}/{len(chunks)} • Total Users: {len(leaderboard_data)}")
|
||||
embed.description = "\n".join(description)
|
||||
|
||||
# Modern footer with stats
|
||||
total_credits = sum(entry["points"] for entry in leaderboard_data)
|
||||
embed.set_footer(
|
||||
text=f"Page {page_num}/{len(chunks)} • {len(leaderboard_data):,} Users • {humanize_number(total_credits)} Total Credits",
|
||||
icon_url=self.bot.user.display_avatar.url
|
||||
)
|
||||
embed.timestamp = datetime.now(timezone.utc)
|
||||
embeds.append(embed)
|
||||
|
||||
view = LeaderboardView(self, ctx, embeds)
|
||||
|
@ -442,30 +456,49 @@ class Leaderboard(commands.Cog):
|
|||
# Debug logging
|
||||
log.info(f"Credits check for {member}: {credits} credits")
|
||||
|
||||
# Get user's rank
|
||||
# Get user's rank and total users for percentage calculation
|
||||
leaderboard_data = await self.get_all_balances()
|
||||
total_users = len(leaderboard_data)
|
||||
rank = next(
|
||||
(i for i, entry in enumerate(leaderboard_data, 1)
|
||||
if entry.get("userId") == str(member.id)),
|
||||
None
|
||||
)
|
||||
|
||||
# Calculate percentage (top x%)
|
||||
percentage = (rank / total_users * 100) if rank and total_users > 0 else None
|
||||
|
||||
embed = discord.Embed(
|
||||
title="🏆 Global Credits",
|
||||
title="", # Modern design: no title needed
|
||||
color=await ctx.embed_color()
|
||||
)
|
||||
|
||||
if credits >= 10000:
|
||||
embed.description = (
|
||||
f"**User:** {member.mention}\n"
|
||||
f"**Credits:** {humanize_number(credits)}\n"
|
||||
f"**Rank:** #{humanize_number(rank) if rank else 'Unranked'}\n"
|
||||
f"**ID:** {member.id}"
|
||||
)
|
||||
else:
|
||||
embed.description = f"{member.mention} has less than 10,000 credits ({humanize_number(credits)} total)"
|
||||
# Modern stat display with emojis and clean formatting
|
||||
stats = [
|
||||
f"💰 **{humanize_number(credits)}** credits",
|
||||
f"📊 Rank **#{humanize_number(rank)}**" if rank else "📊 Unranked",
|
||||
f"🎯 Top **{percentage:.1f}%**" if percentage else "",
|
||||
f"🆔 `{member.id}`"
|
||||
]
|
||||
|
||||
embed.set_thumbnail(url=member.display_avatar.url)
|
||||
embed.description = "\n".join(s for s in stats if s) # Only include non-empty stats
|
||||
else:
|
||||
embed.description = f"💰 **{humanize_number(credits)}** credits\n❗ *Minimum 10,000 credits needed for ranking*"
|
||||
|
||||
# Modern avatar display
|
||||
embed.set_author(
|
||||
name=member.display_name,
|
||||
icon_url=member.display_avatar.url
|
||||
)
|
||||
|
||||
# Add a subtle footer with timestamp
|
||||
embed.set_footer(
|
||||
text="Global Leaderboard Stats",
|
||||
icon_url=ctx.guild.icon.url if ctx.guild.icon else None
|
||||
)
|
||||
embed.timestamp = datetime.now(timezone.utc)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@globalboard.command(name="resync")
|
||||
|
|
Loading…
Add table
Reference in a new issue