Skip to content

Commit

Permalink
Truncate leaderboard message if it exceeds 2000 characters (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
eashwar authored Jun 10, 2024
1 parent 65d1b9a commit 4f9702d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/commands/subcommands/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ const calculateLeaderboardForSeason = async (
response.push(`${idx}. <@${row.userId}> : ${row.points}`);
}

let finalMessage = response.join('\n');

if (finalMessage.length > 2_000) {
const truncatedResponse = response.slice(0, 11);

truncatedResponse.splice(1, 0, '*Only displaying top 10 due to message length limit.*');

finalMessage = truncatedResponse.join('\n');
}

await interaction.reply({
content: response.join('\n'),
content: finalMessage,
ephemeral: true,
});
};
Expand Down Expand Up @@ -85,6 +95,16 @@ const calculateLeaderboardForWeek = async (
response.push(`${idx}. <@${entry.userId}> : [${entry.reacts}](${entry.messageUrl})`);
}

let finalMessage = response.join('\n');

if (finalMessage.length > 2_000) {
const truncatedResponse = response.slice(0, 11);

truncatedResponse.splice(1, 0, '*Only displaying top 10 due to message length limit.*');

finalMessage = truncatedResponse.join('\n');
}

await interaction.reply({
content: response.join('\n'),
ephemeral: true,
Expand Down

0 comments on commit 4f9702d

Please sign in to comment.