mirror of
https://github.com/nx-bat/pet-the-pond.git
synced 2026-09-22 10:29:11 -04:00
leaderboard
This commit is contained in:
@@ -8,6 +8,7 @@ import config from "../../config";
|
|||||||
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
||||||
.setContexts(Constants.InteractionContextType.Guild)
|
.setContexts(Constants.InteractionContextType.Guild)
|
||||||
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
||||||
|
.setMemberPermission(Constants.PermissionFlagsBits.Administrator)
|
||||||
)
|
)
|
||||||
class InitCommand extends Command<CommandClient> {
|
class InitCommand extends Command<CommandClient> {
|
||||||
users = [
|
users = [
|
||||||
|
|||||||
@@ -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<CommandClient> {
|
|
||||||
users = [
|
|
||||||
'1363132678022631428', // nxbat
|
|
||||||
'454653142500507649' // bitdash
|
|
||||||
];
|
|
||||||
|
|
||||||
async handleCommand(context: CommandClient<any, any>, 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');
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import init from "./admin/init";
|
import init from "./admin/init";
|
||||||
import prune from "./admin/prune";
|
|
||||||
import leaderboard from "./leaderboard";
|
import leaderboard from "./leaderboard";
|
||||||
import optin from "./privacy/optin";
|
import optin from "./privacy/optin";
|
||||||
import optout from "./privacy/optout";
|
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];
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class OptInCommand extends Command<CommandClient> {
|
|||||||
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction) {
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction) {
|
||||||
await interaction.defer(true);
|
await interaction.defer(true);
|
||||||
|
|
||||||
const _user = await getUser(interaction.user.id);
|
|
||||||
await updateUserSettings(interaction.user.id, { participating: true });
|
await updateUserSettings(interaction.user.id, { participating: true });
|
||||||
|
|
||||||
await interaction.createMessage({
|
await interaction.createMessage({
|
||||||
|
|||||||
@@ -14,19 +14,6 @@ class ProfileCommand extends Command<CommandClient> {
|
|||||||
|
|
||||||
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction) {
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction) {
|
||||||
await interaction.defer();
|
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({
|
await interaction.createMessage({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
|
|||||||
Vendored
-9
@@ -1,7 +1,3 @@
|
|||||||
export type UserFlags = {
|
|
||||||
blacklisted: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type UserSettings = {
|
export type UserSettings = {
|
||||||
participating: boolean;
|
participating: boolean;
|
||||||
};
|
};
|
||||||
@@ -14,11 +10,6 @@ export type UserStatistics = {
|
|||||||
* Database User.
|
* Database User.
|
||||||
*/
|
*/
|
||||||
export type User = {
|
export type User = {
|
||||||
/**
|
|
||||||
* User flags.
|
|
||||||
*/
|
|
||||||
flags: UserFlags;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User settings specific to each user.
|
* User settings specific to each user.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+21
-12
@@ -50,18 +50,6 @@ export async function deleteUser(userId: string): Promise<void> {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateUserFlags(userId: string, flags: Partial<User["flags"]>): Promise<void> {
|
|
||||||
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<User["settings"]>): Promise<void> {
|
export async function updateUserSettings(userId: string, settings: Partial<User["settings"]>): Promise<void> {
|
||||||
await client`
|
await client`
|
||||||
UPDATE users
|
UPDATE users
|
||||||
@@ -85,3 +73,24 @@ export async function updateUserStatistics(userId: string, statistics: Partial<U
|
|||||||
WHERE user_id = ${userId}
|
WHERE user_id = ${userId}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region Leaderboard
|
||||||
|
|
||||||
|
export async function getHighestPets(limit = 10): Promise<{ userId: string, pets: number }[]> {
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user