2023-12-27 21:43:40 +01:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
|
|
|
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
2024-02-14 20:11:28 +01:00
|
|
|
const { getUserRegistration, getRecentBeatenGameEntry, getBeatenGameCount, getPlanningGameCount, getPlayingGameCount } = require('../../databaseHelperFunctions.js');
|
2023-12-27 21:43:40 +01:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('recentbeat')
|
|
|
|
.setDescription('Get the most recent game you have beat.')
|
|
|
|
.addUserOption(option => option.setName('user').setDescription('The user to check')),
|
|
|
|
async execute(interaction) {
|
2024-03-28 22:12:28 +01:00
|
|
|
await interaction.deferReply();
|
|
|
|
|
2023-12-27 21:43:40 +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 "${interaction.user.username}".`, ephemeral: true });
|
2023-12-27 21:43:40 +01:00
|
|
|
|
2024-02-11 20:42:07 +01:00
|
|
|
const gameDatabaseEntry = await getRecentBeatenGameEntry(userDatabaseEntry.id);
|
2024-03-28 22:12:28 +01:00
|
|
|
if (!gameDatabaseEntry) return interaction.editReply({ content: 'No game found.', ephemeral: true });
|
2023-12-27 21:43:40 +01:00
|
|
|
|
|
|
|
const body = `where id = ${ gameDatabaseEntry.igdb_id }; fields *;`;
|
|
|
|
const res = await getGameJson(body);
|
2024-03-28 22:12:28 +01:00
|
|
|
if (!res) return interaction.editReply({ content: 'No game found.', ephemeral: true });
|
2023-12-27 21:43:40 +01:00
|
|
|
const game = res[0];
|
|
|
|
|
2024-02-14 20:11:28 +01:00
|
|
|
const beatNum = await getBeatenGameCount(userDatabaseEntry);
|
|
|
|
const planNum = await getPlanningGameCount(userDatabaseEntry);
|
|
|
|
const playNum = await getPlayingGameCount(userDatabaseEntry);
|
2023-12-27 21:43:40 +01:00
|
|
|
|
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setColor(0xFFD700)
|
|
|
|
.setAuthor({ name: `${user.displayName}'s most recent beat game!`, iconURL: user.avatarURL() })
|
|
|
|
.setTitle(game.name)
|
|
|
|
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
2024-03-01 18:03:30 +01:00
|
|
|
.setTimestamp();
|
2024-02-14 20:11:28 +01:00
|
|
|
|
|
|
|
if (game.cover) {
|
|
|
|
const coverUrl = await getCoverURL(game.cover);
|
|
|
|
embed.setThumbnail(`${coverUrl}`);
|
|
|
|
}
|
2023-12-27 21:43:40 +01:00
|
|
|
|
2024-03-18 21:47:32 +01:00
|
|
|
embed.addFields({ name: 'Planned', value: `${planNum} game(s)`, inline: true });
|
|
|
|
embed.addFields({ name: 'Now Playing', value: `${playNum} game(s)`, inline: true });
|
|
|
|
embed.addFields({ name: 'Beaten', value: `${beatNum}/100 (${100 - beatNum} game(s) remaining)`, inline: true });
|
2024-03-01 18:03:30 +01:00
|
|
|
|
2024-03-28 22:12:28 +01:00
|
|
|
return interaction.editReply({ embeds: [embed] });
|
2023-12-27 21:43:40 +01:00
|
|
|
},
|
|
|
|
};
|