From d53240589a1eca033c6446a209de0f8886379a78 Mon Sep 17 00:00:00 2001 From: Nix Krystik Date: Wed, 26 Aug 2026 19:51:46 +0800 Subject: [PATCH] leaderboard --- src/commands/admin/init.ts | 1 + src/commands/admin/prune.ts | 29 ----------------------------- src/commands/index.ts | 3 +-- src/commands/privacy/optin.ts | 1 - src/commands/profile.ts | 13 ------------- src/types/database.d.ts | 9 --------- src/utils/database.ts | 33 +++++++++++++++++++++------------ 7 files changed, 23 insertions(+), 66 deletions(-) delete mode 100644 src/commands/admin/prune.ts diff --git a/src/commands/admin/init.ts b/src/commands/admin/init.ts index adba8ab..ceaad68 100644 --- a/src/commands/admin/init.ts +++ b/src/commands/admin/init.ts @@ -8,6 +8,7 @@ import config from "../../config"; .setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall) .setContexts(Constants.InteractionContextType.Guild) .setCommandType(Constants.ApplicationCommandType.ChatInput) + .setMemberPermission(Constants.PermissionFlagsBits.Administrator) ) class InitCommand extends Command { users = [ diff --git a/src/commands/admin/prune.ts b/src/commands/admin/prune.ts deleted file mode 100644 index c13f6a3..0000000 --- a/src/commands/admin/prune.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from "athena-prime"; -import { deleteUser } from "../../utils"; - -// ---------- - -@SlashCommand( - new CommandBuilder('prune', 'Prune users from the database.') - .setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall) - .setContexts(Constants.InteractionContextType.Guild) - .setCommandType(Constants.ApplicationCommandType.ChatInput) - .addUserOption('member', 'The member to prune.') -) -class PruneCommand extends Command { - users = [ - '1363132678022631428', // nxbat - '454653142500507649' // bitdash - ]; - - async handleCommand(context: CommandClient, interaction: CommandInteraction) { - await interaction.defer(true); - - const user = interaction.getRequiredUser('member'); - await deleteUser(user.id); - - await interaction.createMessage({ content: `Pruned: *${user.username}* | ID: ${user.id}` }); - } -} - -export default new PruneCommand('prune'); diff --git a/src/commands/index.ts b/src/commands/index.ts index f858218..c3b29f9 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,5 +1,4 @@ import init from "./admin/init"; -import prune from "./admin/prune"; import leaderboard from "./leaderboard"; import optin from "./privacy/optin"; import optout from "./privacy/optout"; @@ -7,4 +6,4 @@ import profile from "./profile"; // ---------- -export default [init, leaderboard, optin, optout, profile, prune]; +export default [init, leaderboard, optin, optout, profile]; diff --git a/src/commands/privacy/optin.ts b/src/commands/privacy/optin.ts index 49cf9c6..678ca10 100644 --- a/src/commands/privacy/optin.ts +++ b/src/commands/privacy/optin.ts @@ -15,7 +15,6 @@ class OptInCommand extends Command { async handleCommand(context: CommandClient, interaction: CommandInteraction) { await interaction.defer(true); - const _user = await getUser(interaction.user.id); await updateUserSettings(interaction.user.id, { participating: true }); await interaction.createMessage({ diff --git a/src/commands/profile.ts b/src/commands/profile.ts index 5296097..9d803e7 100644 --- a/src/commands/profile.ts +++ b/src/commands/profile.ts @@ -14,19 +14,6 @@ class ProfileCommand extends Command { async handleCommand(context: CommandClient, interaction: CommandInteraction) { await interaction.defer(); - const _user = await getUser(interaction.user.id); - - // Check if user has been blacklisted. - if (_user.flags.blacklisted) { - await interaction.createMessage({ - embeds: [{ - color: 0xff5555, - description: 'There was an error processing your request. Please try again later.' - }] - }); - - return; - } await interaction.createMessage({ embeds: [{ diff --git a/src/types/database.d.ts b/src/types/database.d.ts index 6ad736c..74923ae 100644 --- a/src/types/database.d.ts +++ b/src/types/database.d.ts @@ -1,7 +1,3 @@ -export type UserFlags = { - blacklisted: boolean; -}; - export type UserSettings = { participating: boolean; }; @@ -14,11 +10,6 @@ export type UserStatistics = { * Database User. */ export type User = { - /** - * User flags. - */ - flags: UserFlags; - /** * User settings specific to each user. */ diff --git a/src/utils/database.ts b/src/utils/database.ts index e5066d5..96dff4f 100644 --- a/src/utils/database.ts +++ b/src/utils/database.ts @@ -50,18 +50,6 @@ export async function deleteUser(userId: string): Promise { `; } -export async function updateUserFlags(userId: string, flags: Partial): Promise { - await client` - UPDATE users - SET data = jsonb_set( - data, - '{flags}', - data->'flags' || ${client.json(flags)} - ) - WHERE user_id = ${userId} - `; -} - export async function updateUserSettings(userId: string, settings: Partial): Promise { await client` UPDATE users @@ -85,3 +73,24 @@ export async function updateUserStatistics(userId: string, statistics: Partial { + const users = await client<{ user_id: string; pets: number }[]>` + 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 + ORDER BY pets DESC, user_id ASC + LIMIT ${limit} + `; + + return users.map(user => ({ + userId: user.user_id, + pets: user.pets + })); +} + +//#endregion