2023-12-27 23:27:55 +01:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
2024-02-11 22:05:07 +01:00
|
|
|
const { getUserRegistration, getBeatenGames, checkGameStorageId } = require('../../databaseHelperFunctions.js');
|
2023-12-27 23:27:55 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('beatlist')
|
|
|
|
.setDescription('Show the list of games you have beaten.')
|
|
|
|
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
|
|
|
async execute(interaction) {
|
2024-03-28 22:12:28 +01:00
|
|
|
await interaction.deferReply();
|
2024-01-01 00:29:08 +01:00
|
|
|
|
2023-12-27 23:27:55 +01:00
|
|
|
let user = interaction.user;
|
|
|
|
const userOption = interaction.options.getUser('user');
|
|
|
|
|
|
|
|
if (userOption) {
|
|
|
|
user = userOption;
|
|
|
|
}
|
|
|
|
|
|
|
|
const userDatabaseEntry = await getUserRegistration(user);
|
2024-03-28 22:12:28 +01:00
|
|
|
if (!userDatabaseEntry) return interaction.editReply({ content: `Issue checking registration with "${user.username}".`, ephemeral: true });
|
2023-12-27 23:27:55 +01:00
|
|
|
|
2024-02-11 22:05:07 +01:00
|
|
|
const beatenGamesDatabaseEntries = await getBeatenGames(userDatabaseEntry.id);
|
2023-12-27 23:27:55 +01:00
|
|
|
let desc = '';
|
|
|
|
|
2024-02-14 20:17:02 +01:00
|
|
|
if (!beatenGamesDatabaseEntries || beatenGamesDatabaseEntries.length == 0) {
|
|
|
|
desc = `${user.displayName} has not beaten any games yet.`;
|
|
|
|
} else {
|
2024-03-18 20:54:35 +01:00
|
|
|
desc = desc.concat('__Total: ', beatenGamesDatabaseEntries.length, '/100__\n');
|
2024-02-28 19:02:18 +01:00
|
|
|
|
2024-02-14 20:17:02 +01:00
|
|
|
for (let i = 0; i < beatenGamesDatabaseEntries.length; i++) {
|
2024-06-09 22:58:41 +02:00
|
|
|
const game = await checkGameStorageId(beatenGamesDatabaseEntries[i].gameId);
|
2024-07-13 17:38:37 +02:00
|
|
|
const date = beatenGamesDatabaseEntries[i].statusLastChanged.toLocaleDateString('en-GB', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '/');
|
2024-03-18 20:54:35 +01:00
|
|
|
desc = desc.concat('**#', (i + 1), ' (', date, ')**: ', game.name, '\n');
|
2024-02-14 20:17:02 +01:00
|
|
|
}
|
2023-12-27 23:27:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(0x6441a5)
|
2024-02-28 19:02:18 +01:00
|
|
|
.setThumbnail(user.avatarURL())
|
|
|
|
.setTitle(`${user.displayName}'s Beaten Games`)
|
2023-12-27 23:27:55 +01:00
|
|
|
.setDescription(desc)
|
|
|
|
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
|
|
|
.setTimestamp();
|
|
|
|
|
2024-03-28 22:12:28 +01:00
|
|
|
return interaction.editReply({ embeds: [embed] });
|
2023-12-27 23:27:55 +01:00
|
|
|
},
|
|
|
|
};
|