fix: Refactor leaderboard display logic to improve readability and structure
This commit is contained in:
parent
bae99da412
commit
9968129235
@ -435,25 +435,24 @@ class LevelingCog(commands.Cog):
|
||||
|
||||
if not sorted_leaderboard_data:
|
||||
main_container.add_item(ui.TextDisplay("The leaderboard is empty!"))
|
||||
return
|
||||
else:
|
||||
for i, (user_id, data) in enumerate(sorted_leaderboard_data[:10], 1):
|
||||
member = guild_members_dict.get(user_id)
|
||||
if not member:
|
||||
continue
|
||||
|
||||
for i, (user_id, data) in enumerate(sorted_leaderboard_data[:10], 1):
|
||||
member = guild_members_dict.get(user_id)
|
||||
if not member:
|
||||
continue
|
||||
# Each user's entry gets its own section and is added to the main_container
|
||||
user_section = ui.Section(accessory=None)
|
||||
main_container.add_item(user_section)
|
||||
|
||||
# Each user's entry gets its own section and is added to the main_container
|
||||
user_section = ui.Section(accessory=None)
|
||||
main_container.add_item(user_section)
|
||||
|
||||
# Add text components to the user_section
|
||||
user_section.add_item(ui.TextDisplay(f"**{i}. {member.display_name}**"))
|
||||
user_section.add_item(ui.TextDisplay(f"Level: {data['level']} | XP: {data['xp']}"))
|
||||
|
||||
# Add separator to the main_container
|
||||
if i < len(sorted_leaderboard_data[:10]): # not the last row
|
||||
separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
main_container.add_item(separator)
|
||||
# Add text components to the user_section
|
||||
user_section.add_item(ui.TextDisplay(f"**{i}. {member.display_name}**"))
|
||||
user_section.add_item(ui.TextDisplay(f"Level: {data['level']} | XP: {data['xp']}"))
|
||||
|
||||
# Add separator to the main_container
|
||||
if i < len(sorted_leaderboard_data[:10]): # not the last row
|
||||
separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
main_container.add_item(separator)
|
||||
|
||||
view = LeaderboardView(ctx.guild.name, sorted_data, guild_members)
|
||||
await ctx.send(view=view)
|
||||
|
Loading…
x
Reference in New Issue
Block a user