diff --git a/src/commands/top.ts b/src/commands/top.ts index c1c12dc..f9c9ed6 100644 --- a/src/commands/top.ts +++ b/src/commands/top.ts @@ -11,7 +11,6 @@ export const data = new SlashCommandBuilder() export async function execute(interaction) { await interaction.deferReply(); - let messageContent = ''; userScore .find({}) .sort({ score: -1 }) // Sort by descending order @@ -20,20 +19,46 @@ export async function execute(interaction) { log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' }); console.log(err); } + if (obj.length < 10) { // Need at least 10 scores for top 10 return interaction.followUp( `There are only ${obj.length} users, we need at least 10!`, ); } + + const embeds : unknown[] = []; + let lbMessageContent = ''; + for (let i = 0; i < 10; i++) { - messageContent += `${i + 1}: <@${obj[i].authorID}>: ${obj[i].score}\n`; // Loop through each user and add their name and score to leaderboard content + lbMessageContent += `${i + 1}: <@${obj[i].authorID}>: ${obj[i].score}\n`; // Loop through each user and add their name and score to leaderboard content } + const leaderboardEmbed = new MessageEmbed() .setTitle('Top Ten!') - .setDescription(messageContent) + .setDescription(lbMessageContent) .setColor('#ffffff'); - interaction.followUp({ embeds: [leaderboardEmbed] }); + embeds.push(leaderboardEmbed); + + let sMessageContent = ''; + const members = interaction.guild.members.cache; + + const serverLeaderBoardArray = obj.filter(o => members.some(m => m.user.id === o.authorID)); + console.log(serverLeaderBoardArray[0]); + if (serverLeaderBoardArray.length < 10) { + for (let i = 0; i < 10; i++) { + sMessageContent += `${i + 1}: <@${serverLeaderBoardArray[i].authorID}>: ${serverLeaderBoardArray[i].score}\n`; + } + + const sLeaderboardEmbed = new MessageEmbed() + .setTitle(`Top Ten in ${interaction.guild.name}!`) + .setDescription(sMessageContent) + .setColor('#ffffff'); + + embeds.push(sLeaderboardEmbed); + } + + interaction.followUp({ embeds: embeds }); }); } \ No newline at end of file