|
@ -11,7 +11,6 @@ export const data = new SlashCommandBuilder() |
|
|
export async function execute(interaction) { |
|
|
export async function execute(interaction) { |
|
|
await interaction.deferReply(); |
|
|
await interaction.deferReply(); |
|
|
|
|
|
|
|
|
let messageContent = ''; |
|
|
|
|
|
userScore |
|
|
userScore |
|
|
.find({}) |
|
|
.find({}) |
|
|
.sort({ score: -1 }) // Sort by descending order
|
|
|
.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' }); |
|
|
log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' }); |
|
|
console.log(err); |
|
|
console.log(err); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (obj.length < 10) { |
|
|
if (obj.length < 10) { |
|
|
// Need at least 10 scores for top 10
|
|
|
// Need at least 10 scores for top 10
|
|
|
return interaction.followUp( |
|
|
return interaction.followUp( |
|
|
`There are only ${obj.length} users, we need at least 10!`, |
|
|
`There are only ${obj.length} users, we need at least 10!`, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const embeds : unknown[] = []; |
|
|
|
|
|
let lbMessageContent = ''; |
|
|
|
|
|
|
|
|
for (let i = 0; i < 10; i++) { |
|
|
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() |
|
|
const leaderboardEmbed = new MessageEmbed() |
|
|
.setTitle('Top Ten!') |
|
|
.setTitle('Top Ten!') |
|
|
.setDescription(messageContent) |
|
|
.setDescription(lbMessageContent) |
|
|
.setColor('#ffffff'); |
|
|
.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 }); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |