feat(bot): ✨ Update leaderboard's design.

This commit is contained in:
Nyeki.py
2024-10-18 15:24:49 -03:00
parent 13aafc3fde
commit fe541e3df3
3 changed files with 22 additions and 22 deletions
+6 -1
View File
@@ -7,7 +7,7 @@ from discord import abc
from discord.ext import commands
from discord.ext.commands import errors
from tortoise import expressions, transactions
from tortoise import expressions, transactions, exceptions as tortoise_exc
import redis.asyncio as aredis
@@ -366,6 +366,11 @@ class Payphone(commands.AutoShardedBot):
elif isinstance(exception, errors.CommandNotFound):
return
elif isinstance(exception, tortoise_exc.TransactionManagementError):
# Tortoise ORM bug. This may need to be logged for debugging, but for now they just
# clutter the logs.
return
else:
return await super().on_command_error(context, exception)
+4
View File
@@ -678,6 +678,10 @@ class Calls(base.Cog):
lambda c: c.id != channel_id, call.channels
)
if other_channel is None:
# BUG: The call wasn't properly set up.
return
user, profile = await utils.get_user(message.author)
call_rss = await models.CallUserChannelRelationship.filter(
+12 -21
View File
@@ -390,37 +390,28 @@ class Users(base.Cog):
top_users = (
await models.User.filter(leaderboard_position__lte=10)
.prefetch_related("profiles")
.order_by("leaderboard_position")
.limit(10)
)
rows = [
[
f"#{pos + 1}",
fmt.trim(user.username, 13),
f"{user.leaderboard_calls_count if user.leaderboard_calls_count is not None else "?"} call{"s" if user.leaderboard_calls_count != 1 else ""}",
]
user_rows = [
f"**#{pos + 1} - {user.profiles[0].name}**{" (You!)" if user.id == ctx.author.id else ""}\nParticipated in {user.leaderboard_calls_count} calls."
for pos, user in enumerate(top_users)
]
if not any(map(lambda u: u.id == ctx.author.id, top_users)):
user, _ = await utils.get_user(ctx.author)
if user.leaderboard_position is not None:
rows.append(
[
f"#{user.leaderboard_position}",
fmt.trim(user.username, 13),
f"{user.leaderboard_calls_count if user.leaderboard_calls_count is not None else "?"} call{"s" if user.leaderboard_calls_count != 1 else ""}",
]
)
table = fmt.monospace_table(rows)
embed = discord.Embed(
color=constants.EMBED_COLOR,
title=f"Monthly Leaderboard ({datetime.now(timezone.utc).strftime("%B")})",
description=f"```\n{table if len(rows) > 0 else "Come back in 15 minutes!"}\n```",
description=(
"Payphone's monthly leaderboard is based on the amount of calls you've "
"participated in with more than 25 messages sent (to prevent spam). The stats are "
"resetted every month.\n"
"\n"
"__**Top Users:**__\n"
"\n"
)
+ "\n\n".join(user_rows),
author=self.bot.embed_author,
footer=discord.EmbedFooter(
text="The leaderboard is updated every 15 minutes."