Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add offline functionality for !top command #683

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ async def top(ctx: Context) -> str | None:
return "Invalid username."

# specific player provided
player = app.state.sessions.players.get(name=ctx.args[1])
if not player:
return "Player not found."
user = await users_repo.fetch_one(name=ctx.args[1])
else:
# no player provided, use self
player = ctx.player
user = await users_repo.fetch_one(id=ctx.player.id)
if not user:
FrostiDrinks marked this conversation as resolved.
Show resolved Hide resolved
return "Player not found."

# !top rx!std
mode = GAMEMODE_REPR_LIST.index(ctx.args[0])
Expand All @@ -397,13 +397,15 @@ async def top(ctx: Context) -> str | None:
"AND s.status = 2 "
"AND b.status in (2, 3) "
"ORDER BY s.pp DESC LIMIT 10",
{"user_id": player.id, "mode": mode},
{"user_id": user["id"], "mode": mode},
)
if not scores:
return "No scores"

user_embed = f"[https://{app.settings.DOMAIN}/u/{user['id']} {user['name']}]"

return "\n".join(
[f"Top 10 scores for {player.embed} ({ctx.args[0]})."]
[f"Top 10 scores for {user_embed} ({ctx.args[0]})."]
+ [
TOP_SCORE_FMTSTR.format(idx=idx + 1, domain=app.settings.DOMAIN, **s)
for idx, s in enumerate(scores)
Expand Down
Loading