TheOchulus/commands/100-games/globalbeatlist.js

39 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-02-16 18:04:29 +01:00
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getAllBeatenGames, checkGameStorageId, getUserFromId } = require('../../databaseHelperFunctions.js');
const { getGameJson } = require('../../igdbHelperFunctions.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('globalbeatlist')
.setDescription('Show a list of all games beaten for the 100 games challenge in chronological order.'),
async execute(interaction) {
await interaction.reply({ content: 'Searching for games...', ephemeral: true });
const user = interaction.user;
const beatenGamesDatabaseEntries = await getAllBeatenGames();
let desc = '';
if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) {
desc = 'No games beaten yet.';
} else {
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
2024-02-16 18:34:08 +01:00
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
2024-02-16 18:04:29 +01:00
const userentry = await getUserFromId(beatenGamesDatabaseEntries[i].userId);
const date = beatenGamesDatabaseEntries[i].updatedAt.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
desc = desc.concat('**', date, '**: \t', game.name, ' \t*(', userentry.username, ')*\n');
}
}
const embed = new EmbedBuilder()
.setColor(0x6441a5)
.setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() })
.setThumbnail(interaction.client.user.avatarURL())
.setTitle('Global Beat List')
.setDescription(desc)
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
.setTimestamp();
return interaction.followUp({ embeds: [embed] });
},
};