2023-12-19 21:42:54 +01:00
const { SlashCommandBuilder } = require ( 'discord.js' ) ;
2023-12-30 02:31:56 +01:00
const { getUserRegistration , deleteBeatenGameNum , checkGameStorageId } = require ( '../../databaseHelperFunctions.js' ) ;
2023-12-19 21:42:54 +01:00
module . exports = {
data : new SlashCommandBuilder ( )
2023-12-30 02:36:41 +01:00
. setName ( 'deletegame' )
2023-12-19 21:42:54 +01:00
. setDescription ( 'Delete a game that you have beaten from the 100 game challenge!' )
. addNumberOption ( option => option . setName ( 'beatgamenumber' ) . setDescription ( 'Index of the game to delete in the list of beaten games.' ) . setMinValue ( 1 ) . setMaxValue ( 100 ) ) ,
async execute ( interaction ) {
const beatGameNumber = interaction . options . getNumber ( 'beatgamenumber' ) ;
const userDatabaseEntry = await getUserRegistration ( interaction . user ) ;
let result ;
2023-12-30 02:31:56 +01:00
if ( beatGameNumber ) {
2023-12-19 21:42:54 +01:00
result = await deleteBeatenGameNum ( beatGameNumber , userDatabaseEntry ) ;
}
2023-12-30 02:36:41 +01:00
else {
2023-12-30 02:55:51 +01:00
const recentGame = await getRecentGameEntry ( userDatabaseEntry . id ) ;
result = await deleteBeatenGameId ( recentGame . id , userDatabaseEntry ) ;
2023-12-30 02:36:41 +01:00
}
2023-12-19 21:42:54 +01:00
if ( result ) {
const game = await checkGameStorageId ( result . gameId ) ;
return interaction . reply ( ` ${ game . name } successfully deleted ` ) ;
}
2023-12-27 22:10:22 +01:00
return interaction . reply ( { content : 'Unable to delete entry / No entry found.' , ephemeral : true } ) ;
2023-12-19 21:42:54 +01:00
} ,
} ;