pets ranking

This commit is contained in:
2026-08-26 20:00:02 +08:00
parent 1271cd5c8e
commit f15aa87523
2 changed files with 40 additions and 5 deletions
+17 -5
View File
@@ -1,5 +1,5 @@
import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from "athena-prime";
import { getUser } from "../utils";
import { getPetPosition, getUser } from "../utils";
// ----------
@@ -16,6 +16,7 @@ class ProfileCommand extends Command<CommandClient> {
await interaction.defer();
const _user = await getUser(interaction.user.id);
const position = await getPetPosition(interaction.user.id);
await interaction.createMessage({
embeds: [{
@@ -26,12 +27,23 @@ class ProfileCommand extends Command<CommandClient> {
color: 0xe77ed1,
// TODO: Add Rankings.
title: `Your Profile | Pet the Pond`,
fields: [
{ name: 'Pets', value: `${_user.statistics.pets}`, inline: true },
{ name: 'Rank', value: 'N/A', inline: true },
{ name: 'Participating', value: _user.settings.participating ? 'Yes' : 'No', inline: false }
{
name: 'Pets',
value: `${_user.statistics.pets}`,
inline: true
},
{
name: 'Rank',
value: position ? `#${position}` : 'N/A',
inline: true
},
{
name: 'Participating',
value: _user.settings.participating ? 'Yes' : 'No',
inline: false
}
],
footer: {
+23
View File
@@ -93,4 +93,27 @@ export async function getHighestPets(limit = 10): Promise<{ userId: string, pets
}));
}
export async function getPetPosition(userId: string): Promise<number | null> {
const result = await client<{ position: number }[]>`
SELECT position
FROM (
SELECT
user_id,
RANK() OVER (ORDER BY pets DESC, user_id ASC) AS position
FROM (
SELECT
user_id,
(data->'statistics'->>'pets')::integer AS pets
FROM users
WHERE
COALESCE((data->'flags'->>'blacklisted')::boolean, false) = false
AND COALESCE((data->'settings'->>'participating')::boolean, true) = true
) ranked
) ranked_users
WHERE user_id = ${userId}
`;
return result[0]?.position ?? null;
}
//#endregion