Skip to content

Commit

Permalink
feat: update accuracy leaderboard command to allow optional week number
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
fearandesire committed Dec 27, 2024
1 parent 059e3ed commit 60eebdb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/predictions/prediction-leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) =>
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -486,6 +491,7 @@ class CreateLeaderboardEmbedParams {
type: 'weekly' | 'monthly' | 'seasonal' | 'allTime';
metadata?: {
thumbnail?: string;
currentWeek?: number;
};
}

Expand Down

0 comments on commit 60eebdb

Please sign in to comment.