Add option to delete all planned games
This commit is contained in:
parent
2e97bab0f5
commit
48aceea554
|
@ -1,20 +1,47 @@
|
|||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { getUserRegistration, deletePlanningGameNum, checkGameStorageId, getRecentPlanningGameEntry, deletePlanningGameId, getPlayingGameCount, getBeatenGameCount, getPlanningGameCount } = require('../../databaseHelperFunctions.js');
|
||||
const { getUserRegistration, deletePlanningGameNum, checkGameStorageId, getRecentPlanningGameEntry, deletePlanningGameId, getPlayingGameCount, getBeatenGameCount, getPlanningGameCount, getPlanningGames } = require('../../databaseHelperFunctions.js');
|
||||
const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('deleteplannedgame')
|
||||
.setDescription('Delete a game that you were planning to play!')
|
||||
.addNumberOption(option => option.setName('currentgamenumber').setDescription('Index of the game to delete in the list of planned games.').setMinValue(1)),
|
||||
.addNumberOption(option => option.setName('currentgamenumber').setDescription('Index of the game to delete in the list of planned games.').setMinValue(1))
|
||||
.addBooleanOption(option => option.setName('deleteallgames').setDescription('Deletes all the games currently planned.')),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply();
|
||||
|
||||
const beatGameNumber = interaction.options.getNumber('currentgamenumber');
|
||||
const deleteAllGames = interaction.options.getBoolean('deleteallgames');
|
||||
|
||||
const userDatabaseEntry = await getUserRegistration(interaction.user);
|
||||
let result;
|
||||
|
||||
if (deleteAllGames) {
|
||||
const databaseEntries = await getPlanningGames(userDatabaseEntry.id);
|
||||
|
||||
for (let i = databaseEntries.length; i > 0; i--) {
|
||||
await deletePlanningGameNum(i, userDatabaseEntry);
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xFF0000)
|
||||
.setAuthor({ name: `${interaction.user.displayName} deleted all planned games!`, iconURL: interaction.user.avatarURL() })
|
||||
.setTitle('Everything deleted!')
|
||||
.setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() })
|
||||
.setTimestamp();
|
||||
|
||||
const beatNum = await getBeatenGameCount(userDatabaseEntry);
|
||||
const planNum = await getPlanningGameCount(userDatabaseEntry);
|
||||
const playNum = await getPlayingGameCount(userDatabaseEntry);
|
||||
|
||||
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 });
|
||||
|
||||
return interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
if (beatGameNumber) {
|
||||
result = await deletePlanningGameNum(beatGameNumber, userDatabaseEntry);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue