feat(bot): ✨ Update leaderboard's design.
This commit is contained in:
+6
-1
@@ -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
|
||||
|
||||
@@ -367,6 +367,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)
|
||||
|
||||
|
||||
@@ -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
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user