mirror of
https://github.com/nx-bat/pet-the-pond.git
synced 2026-09-22 10:29:11 -04:00
pets ranking
This commit is contained in:
+17
-5
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user