From 698a888ae124cee0c0cc8943ac4bac29e1e051b0 Mon Sep 17 00:00:00 2001 From: baz Date: Fri, 10 Jan 2025 18:16:32 +0000 Subject: [PATCH] Add year option to leaderboard --- commands/100-games/leaderboard.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/commands/100-games/leaderboard.js b/commands/100-games/leaderboard.js index 0c1fe66..67b6aaa 100644 --- a/commands/100-games/leaderboard.js +++ b/commands/100-games/leaderboard.js @@ -1,15 +1,27 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); -const { getLeaderboardEntries } = require('../../databaseHelperFunctions.js'); +const { getLeaderboardEntries, getLeaderboardEntriesBetweenDates } = require('../../databaseHelperFunctions.js'); module.exports = { data: new SlashCommandBuilder() .setName('leaderboard') - .setDescription('Show the leaderboard!'), + .setDescription('Show the leaderboard!') + .addIntegerOption(option => option.setName('year').setDescription('The year to check').addChoices({ name: '2024', value: 2024 }, { name: '2025', value: 2025 })), async execute(interaction) { - const leaderboard = await getLeaderboardEntries(); await interaction.deferReply(); + const yearOption = interaction.options.getInteger('year'); + + let leaderboard; + + if (yearOption) { + leaderboard = await getLeaderboardEntriesBetweenDates(`${yearOption}-01-01`, `${yearOption}-12-31`); + } + else { + leaderboard = await getLeaderboardEntries(); + } + + if (!leaderboard) return interaction.editReply({ content: 'There was a problem!', ephemeral: true }); let desc = '';