TheOchulus/commands/100-games/leaderboard.js

58 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2023-12-19 23:19:08 +01:00
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getLeaderboardEntries } = require('../../databaseHelperFunctions.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('leaderboard')
.setDescription('Show the leaderboard!'),
async execute(interaction) {
const leaderboard = await getLeaderboardEntries();
await interaction.deferReply();
2023-12-19 23:19:08 +01:00
if (!leaderboard) return interaction.editReply({ content: 'There was a problem!', ephemeral: true });
2023-12-19 23:19:08 +01:00
await leaderboard.sort((a, b) => parseInt(b.count) - parseInt(a.count));
let desc = '';
2024-04-20 17:24:37 +02:00
let count = 0;
for (let i = 0; i < leaderboard.length; i++) {
if (leaderboard[i].count > 0) {
count += leaderboard[i].count;
}
}
desc = desc.concat('__Total: ', count, '__');
2023-12-19 23:19:08 +01:00
for (let i = 0; i < leaderboard.length; i++) {
if (leaderboard[i].count > 0) {
2024-02-28 19:12:04 +01:00
let newLine = String.prototype.concat(leaderboard[i].username, ' - ', leaderboard[i].count, ' games');
const number = String.prototype.concat('**#', (i + 1), '** ');
if (i == 0) newLine = String.prototype.concat('**', newLine, '**');
if (leaderboard[i].username == interaction.user.username) newLine = String.prototype.concat('*', newLine, '*');
2024-02-28 19:12:04 +01:00
newLine = String.prototype.concat(number, newLine);
newLine = String.prototype.concat('\n', newLine);
desc = String.prototype.concat(desc, newLine);
}
2023-12-19 23:19:08 +01:00
}
const embed = new EmbedBuilder()
.setColor(0x6441a5)
.setTitle('The 100 Games Challenge Leaderboard!')
.setDescription(desc)
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
.setTimestamp();
return interaction.editReply({ embeds: [embed] });
2023-12-19 23:19:08 +01:00
},
};