From 60eebdb6fb6ef6d681b854b4412d0c4db7bb9a6b Mon Sep 17 00:00:00 2001 From: fearandesire Date: Fri, 27 Dec 2024 16:09:51 -0500 Subject: [PATCH] feat: update accuracy leaderboard command to allow optional week number - Modified the accuracy leaderboard command to accept an optional week number parameter, improving flexibility for users. - Updated the handling of the week number to default to null if not provided, ensuring compatibility with existing functionality. - Enhanced the leaderboard embed to display the correct week title based on the provided or current week number, improving user experience. --- src/commands/predictions/prediction-leaderboard.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/commands/predictions/prediction-leaderboard.ts b/src/commands/predictions/prediction-leaderboard.ts index c4719660..56a8930f 100644 --- a/src/commands/predictions/prediction-leaderboard.ts +++ b/src/commands/predictions/prediction-leaderboard.ts @@ -22,7 +22,7 @@ export class UserCommand extends Command { builder .setName('accuracy_leaderboard') .setDescription(this.description) - .setDMPermission(false) + .setContexts([0]) .addSubcommand((subcommand) => subcommand .setName('weekly') @@ -32,7 +32,7 @@ export class UserCommand extends Command { .setName('week_number') .setDescription('The week number to view.') .setMinValue(1) - .setRequired(true), + .setRequired(false), ), ) .addSubcommand((subcommand) => @@ -95,7 +95,8 @@ export class UserCommand extends Command { private async handleWeeklyLeaderboard( interaction: Command.ChatInputCommandInteraction, ) { - const weekNumber = interaction.options.getInteger('week_number', true); + const weekNumber = + interaction.options.getInteger('week_number', false) ?? null; const guildId = interaction.guildId; const currentYear = new Date().getFullYear(); @@ -125,10 +126,14 @@ export class UserCommand extends Command { }); } + const weeklyTitle = weekNumber + ? `Week ${weekNumber}` + : `Week ${leaderboard?.current_week}`; const embed = await this.createLeaderboardEmbed({ leaderboardData: parsedLeaderboard, type: 'weekly', - metadata: { thumbnail }, + title: weeklyTitle, + metadata: { thumbnail, currentWeek: leaderboard?.current_week }, }); const pagination = new Pagination(); const components = pagination.createPaginationButtons( @@ -486,6 +491,7 @@ class CreateLeaderboardEmbedParams { type: 'weekly' | 'monthly' | 'seasonal' | 'allTime'; metadata?: { thumbnail?: string; + currentWeek?: number; }; }