From 48697acfb99392b47bbd5081583a574555ddfb68 Mon Sep 17 00:00:00 2001 From: ForGetFulSkyBro Date: Tue, 28 Nov 2023 12:48:50 -0500 Subject: [PATCH] add: leaderboard (unfinished) --- package.json | 3 +- pnpm-lock.yaml | 106 +++++++++++++++++++++++++++++++ src/buttons/result.ts | 1 + src/commands/game/leaderboard.ts | 69 ++++++++++++++++++++ src/commands/settings/custom.ts | 1 + src/util/pagination.ts | 4 ++ 6 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 src/commands/game/leaderboard.ts diff --git a/package.json b/package.json index d3f1d7c5..0cb6bbf6 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@sentry/node": "^7.80.1", "@top-gg/sdk": "^3.1.5", "axios": "^1.6.2", + "canvabase": "^1.1.1", "chalk-advanced": "^1.0.3", "cron": "^3.1.6", "cryptr": "^6.3.0", @@ -65,4 +66,4 @@ "tslib": "^2.6.2", "typescript": "^5.2.2" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb86c43c..ef8ad01a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ dependencies: axios: specifier: ^1.6.2 version: 1.6.2 + canvabase: + specifier: ^1.1.1 + version: 1.1.1 chalk-advanced: specifier: ^1.0.3 version: 1.0.7 @@ -175,6 +178,15 @@ packages: sparse-bitfield: 3.0.3 dev: false + /@napi-rs/canvas-android-arm64@0.1.35: + resolution: {integrity: sha512-jBsiAX+S1Ps7xHuk0LCeDdZi4pD9gU3AK/M2dM5PHQnV12D+rmp5Ribu8rvPt2EpAgRYvUsyPSpjrQs/+hxHnA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-android-arm64@0.1.44: resolution: {integrity: sha512-3UDlVf1CnibdUcM0+0xPH4L4/d/tCI895or0y7mr/Xlaa1tDmvcQCvBYl9G54IpXsm+e4T1XkVrGGJD4k1NfSg==} engines: {node: '>= 10'} @@ -184,6 +196,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-darwin-arm64@0.1.35: + resolution: {integrity: sha512-IY9uhVr5o412gHUmj7AvN+equsGtmi6L4hPN4p2VkQcSplpZgEQIgsgk5Oys91KjuQUSFG2Dr24Uv832k5xfcQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-darwin-arm64@0.1.44: resolution: {integrity: sha512-Y1Yx0H45Iicx2b6pcrlICjlwgylLtqi0t5OJgeUXnxLcJ1+aEpmjLr16tddqHkmGUw/nBRAwfPJrf3GaOwWowQ==} engines: {node: '>= 10'} @@ -193,6 +214,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-darwin-x64@0.1.35: + resolution: {integrity: sha512-yY4s3H2wgAsQa/qAQaGiz43NWzLSdEAeZ3rATYhaAQg2vWd+uiU2FGBf5b7OOZwEQ8oGTa8qvwMATQ82K5hUlA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-darwin-x64@0.1.44: resolution: {integrity: sha512-gbzeNz13DFH0Ak5ENyQ5ZEuSuCjNDxA/OV9P5f19lywbOVL5Ol+qgKX0BXBcP3O3IXWahruOvmmLUBn9h1MHpA==} engines: {node: '>= 10'} @@ -202,6 +232,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-linux-arm-gnueabihf@0.1.35: + resolution: {integrity: sha512-ZY/ilgsm1jLhOkcVw9IEOPS5tGrqUbs0kBoWn5psolyeMNZW0o3fUMbyM/ebkb+8BeWTmLLrpx47kfaSOp05hA==} + engines: {node: '>= 10'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-linux-arm-gnueabihf@0.1.44: resolution: {integrity: sha512-Sad3/eGyzTZiyJFeFrmX1M3aRp0n3qTAXeCm6EeAjCFGk8TWd4cINCGT3IRY4wmCvNnpe6C4fM03K07cU5YYwA==} engines: {node: '>= 10'} @@ -211,6 +250,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-linux-arm64-gnu@0.1.35: + resolution: {integrity: sha512-NUAsUnN8ZaBM9RGrETYKz1VCGuqMaszT2TYojM2MlAg2PwcOVeSGWfPG9ZYaobCr++LSY+PB4x2JKOhBwIRfkQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-linux-arm64-gnu@0.1.44: resolution: {integrity: sha512-bCrI9naYGPRFHePMGN+wlrWzC+Swi6uc1YzFg4/wOYzHKSte8FXHrGspHOPPr12BCEmgg3yXK8nnLjxGdlAWtg==} engines: {node: '>= 10'} @@ -220,6 +268,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-linux-arm64-musl@0.1.35: + resolution: {integrity: sha512-93RjEir8WomM8DbtvLTAmsaB11mc/kqR3lZM8dHqyIWEXhVJRKb8PEn52aa2EmWkINlqgyZgdx8Ch8QOzFC0bQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-linux-arm64-musl@0.1.44: resolution: {integrity: sha512-gB/ao9zBQaOJik4arOKJisZaG+v7DuyBW7UdG+0L80msAuJTTH2UgWOnmXfZwPxzxNbFKzOa8r48uVzfTaAHGQ==} engines: {node: '>= 10'} @@ -229,6 +286,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-linux-x64-gnu@0.1.35: + resolution: {integrity: sha512-DEmNXbxUyLVD5cdJaG21cPMmexgkHq5hf1bnnGb4lIODjffR6appiLwEmFCYCRpujn+mH/ZrDRPc30zVEBTWLA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-linux-x64-gnu@0.1.44: resolution: {integrity: sha512-pvHy1bJ0DDD4Bsx6yuFnqpIyBW7+2iIK5BpvmL36zXE+7w2MEeaYzLUWTBhrXj8rzHys6MwLmHNlkw65R80YbQ==} engines: {node: '>= 10'} @@ -238,6 +304,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-linux-x64-musl@0.1.35: + resolution: {integrity: sha512-ZTenigydKsGOOU8JEFWsFVc9XF9D/bn+EPak1zJ/nj3HoUWxCLeoDZnKW9KrLyyBPueb9jnErT8rt1FtzK/mpQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-linux-x64-musl@0.1.44: resolution: {integrity: sha512-5QaeYqNZ/u1QI2E/UqvnmuORT6cI1qTtLosPp/y4awaK+/LXQEzotHNv0nan0z4EV/0mXsJswY9JpISRJzx+Kw==} engines: {node: '>= 10'} @@ -247,6 +322,15 @@ packages: dev: false optional: true + /@napi-rs/canvas-win32-x64-msvc@0.1.35: + resolution: {integrity: sha512-XeT2emnlz/xgMh+i/lhuG7tHHQSnMM8wMyZEfq8lXQ6LrFWEEuTvhrJ7UWJKJ7KgSFIucJY8VC0Ea3M94kp0Cg==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + /@napi-rs/canvas-win32-x64-msvc@0.1.44: resolution: {integrity: sha512-pbeTGLox+I+sMVl/FFO21Xvp0PhijsuEr9gaynmN2X7FPTg+CCuuBDhfSU5iMAtcCCYFCk8ridZIWy5jkcf72w==} engines: {node: '>= 10'} @@ -256,6 +340,21 @@ packages: dev: false optional: true + /@napi-rs/canvas@0.1.35: + resolution: {integrity: sha512-D/NiDAPPfqrzDLRHJCQv0AZF6LBJx89FIg0ZUhoerkfi3ZIR0IjdCuul2MynHO+2bRvIH8jYA9maFksZyg4rVQ==} + engines: {node: '>= 10'} + optionalDependencies: + '@napi-rs/canvas-android-arm64': 0.1.35 + '@napi-rs/canvas-darwin-arm64': 0.1.35 + '@napi-rs/canvas-darwin-x64': 0.1.35 + '@napi-rs/canvas-linux-arm-gnueabihf': 0.1.35 + '@napi-rs/canvas-linux-arm64-gnu': 0.1.35 + '@napi-rs/canvas-linux-arm64-musl': 0.1.35 + '@napi-rs/canvas-linux-x64-gnu': 0.1.35 + '@napi-rs/canvas-linux-x64-musl': 0.1.35 + '@napi-rs/canvas-win32-x64-msvc': 0.1.35 + dev: false + /@napi-rs/canvas@0.1.44: resolution: {integrity: sha512-IyhSndjw29LR1WqkUZvTJI4j8Ve1QGbZYtpdQjJjcFvsvJS4/WHzOWV8ZciLPJBhrYvSQf/JbZJy5LHmFV+plg==} engines: {node: '>= 10'} @@ -572,6 +671,13 @@ packages: get-intrinsic: 1.2.1 dev: false + /canvabase@1.1.1: + resolution: {integrity: sha512-XORtLX7RdBw0hayk2bnRsf1+AsV+LZIemNFuB5Gh+XI1oqiLWSfyhsEPLF5g2iy8LLR2U1LULKlZAEVuTE5mJQ==} + engines: {node: '>=16.9.0'} + dependencies: + '@napi-rs/canvas': 0.1.35 + dev: false + /chalk-advanced@1.0.7: resolution: {integrity: sha512-AxYlvmX+vnDas35hKRInHxHMaUNyOlY2OKywpr8U7CQITSEymbEZtV/kWnV/MJqNXae6vDoKdgGExdaXe8cusQ==} dev: false diff --git a/src/buttons/result.ts b/src/buttons/result.ts index 9b5bda31..98133dd8 100644 --- a/src/buttons/result.ts +++ b/src/buttons/result.ts @@ -30,6 +30,7 @@ const button: Button = { user: interaction.user.id, timeout: 180000, client, + image: null, }); page.add( diff --git a/src/commands/game/leaderboard.ts b/src/commands/game/leaderboard.ts new file mode 100644 index 00000000..06ce55aa --- /dev/null +++ b/src/commands/game/leaderboard.ts @@ -0,0 +1,69 @@ +import { + EmbedBuilder, + SlashCommandBuilder, + ActionRowBuilder, + ButtonBuilder, + MessageActionRowComponentBuilder, + bold, +} from "discord.js"; +import { captureException } from "@sentry/node"; +import { ChatInputCommand } from "../../models"; +import Paginator from "../../util/pagination"; +import { UserModel } from "../../util/Models/userModel"; +import Canvas from "canvabase"; + +const command: ChatInputCommand = { + requireGuild: true, + data: new SlashCommandBuilder() + .setName("leaderboard") + .setDescription("Leaderboard statistics for games") + .setDMPermission(false) + .setDescriptionLocalizations({ + de: "Test", + "es-ES": "Test", + fr: "Test", + }) + .addStringOption((option) => + option + .setName("game") + .setDescription("Which game do you want leaderboards from?") + .addChoices({ name: "Higher & Ligher", value: "higherlower" }) + .setRequired(true), + ) + .addStringOption((option) => + option + .setName("for") + .setDescription("Pick what type of leaderboard you want to view") + .addChoices( + { name: "Global", value: "global" }, + { name: "Local", value: "local" }, + ) + .setRequired(true), + ), + + /** + * @param {CommandInteraction} interaction + * @param {WouldYou} client + * @param {guildModel} guildDb + */ + execute: async (interaction, client, guildDb) => { + switch (interaction.options.getString("game")) { + case "higherlower": + const page = new Paginator({ + user: interaction.user.id, + timeout: 180000, + client, + image: null, + }); + + const users = await UserModel.find({ + "higherlower.highscore": { $gt: 1 }, + }); + + + break; + } + }, +}; + +export default command; diff --git a/src/commands/settings/custom.ts b/src/commands/settings/custom.ts index e5f666d7..7288b095 100644 --- a/src/commands/settings/custom.ts +++ b/src/commands/settings/custom.ts @@ -383,6 +383,7 @@ const command: ChatInputCommand = { user: interaction.user.id, timeout: 180000, client, + image: null, }); if ( diff --git a/src/util/pagination.ts b/src/util/pagination.ts index 7e6252d0..e4e8658f 100644 --- a/src/util/pagination.ts +++ b/src/util/pagination.ts @@ -13,21 +13,25 @@ export default class Paginator { private user: any; private page: number; private timeout: number; + private image: string | null; constructor({ user, client, timeout, + image, }: { user: any; client: WouldYou; timeout: number; + image: string | null; }) { this.pages = []; this.client = client; this.user = user; this.page = 0; this.timeout = timeout; + this.image = image; } add(page: EmbedBuilder) {