2024-02-11 21:33:11 +00:00
const { SlashCommandBuilder , EmbedBuilder } = require ( 'discord.js' ) ;
const { getUserRegistration , deletePlayingGameNum , checkGameStorageId , getRecentPlayingGameEntry , deletePlayingGameId , getPlayingGameCount , getBeatenGameCount , getPlanningGameCount } = require ( '../../databaseHelperFunctions.js' ) ;
const { getCoverURL , getGameJson } = require ( '../../igdbHelperFunctions.js' ) ;
module . exports = {
data : new SlashCommandBuilder ( )
. setName ( 'deleteplayinggame' )
. setDescription ( 'Delete a game that you was playing!' )
. addNumberOption ( option => option . setName ( 'currentgamenumber' ) . setDescription ( 'Index of the game to delete in the list of currently playing games.' ) . setMinValue ( 1 ) ) ,
async execute ( interaction ) {
2024-03-28 21:12:28 +00:00
await interaction . deferReply ( ) ;
2024-02-11 21:33:11 +00:00
const beatGameNumber = interaction . options . getNumber ( 'currentgamenumber' ) ;
const userDatabaseEntry = await getUserRegistration ( interaction . user ) ;
let result ;
if ( beatGameNumber ) {
result = await deletePlayingGameNum ( beatGameNumber , userDatabaseEntry ) ;
}
else {
const recentGame = await getRecentPlayingGameEntry ( userDatabaseEntry . id ) ;
result = await deletePlayingGameId ( recentGame . id , userDatabaseEntry ) ;
}
if ( result ) {
const gameDatabaseEntry = await checkGameStorageId ( result . gameId ) ;
const body = ` where id = ${ gameDatabaseEntry . igdb _id } ; fields *; ` ;
const res = await getGameJson ( body ) ;
2024-03-28 21:12:28 +00:00
if ( ! res ) return interaction . editReply ( { content : 'No game found.' , ephemeral : true } ) ;
2024-02-11 21:33:11 +00:00
const game = res [ 0 ] ;
const beatNum = await getBeatenGameCount ( userDatabaseEntry ) ;
const planNum = await getPlanningGameCount ( userDatabaseEntry ) ;
const playNum = await getPlayingGameCount ( userDatabaseEntry ) ;
const embed = new EmbedBuilder ( )
. setColor ( 0xFF0000 )
. setAuthor ( { name : ` ${ interaction . user . displayName } deleted a game! ` , iconURL : interaction . user . avatarURL ( ) } )
. setTitle ( ` ${ game . name } deleted! ` )
2025-02-09 23:48:44 +00:00
. setURL ( game . url )
2024-02-11 21:33:11 +00:00
. setFooter ( { text : 'The Ochulus • 100 Games Challenge' , iconURL : interaction . client . user . avatarURL ( ) } )
. setTimestamp ( ) ;
2025-02-09 23:38:59 +00: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-02-14 19:11:28 +00:00
if ( game . cover ) {
const coverUrl = await getCoverURL ( game . cover ) ;
embed . setThumbnail ( ` ${ coverUrl } ` ) ;
}
2024-03-28 21:12:28 +00:00
return interaction . editReply ( { embeds : [ embed ] } ) ;
2024-02-11 21:33:11 +00:00
}
2024-03-28 21:12:28 +00:00
return interaction . editReply ( { content : 'Unable to delete entry / No entry found.' , ephemeral : true } ) ;
2024-02-11 21:33:11 +00:00
} ,
} ;