From 05b8cfa228c47d679053caac48e93848b6fda220 Mon Sep 17 00:00:00 2001 From: baz Date: Tue, 10 Jun 2025 15:49:24 +0100 Subject: [PATCH] Add option to view games with missing length info to totalbeatlength --- commands/100-games/totalbeatlength.js | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/commands/100-games/totalbeatlength.js b/commands/100-games/totalbeatlength.js index 6c71ca5..d9986f2 100644 --- a/commands/100-games/totalbeatlength.js +++ b/commands/100-games/totalbeatlength.js @@ -6,12 +6,14 @@ module.exports = { data: new SlashCommandBuilder() .setName('totalbeatlength') .setDescription('Calculate the time taken to beat every game on a users beat games list.') - .addUserOption(option => option.setName('user').setDescription('The user to check')), + .addUserOption(option => option.setName('user').setDescription('The user to check')) + .addBooleanOption(option => option.setName('showmissing').setDescription('Replaces the output with a list of games with missing length information')), async execute(interaction) { await interaction.deferReply(); let user = interaction.user; const userOption = interaction.options.getUser('user'); + const showmissingOption = interaction.options.getBoolean('showmissing'); if (userOption) { user = userOption; @@ -40,7 +42,7 @@ module.exports = { gameIds.push(game.igdb_id); } - const beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`)); + let beatGameIGDBEntries = await getGameJson(String.prototype.concat(`where id = (${gameIds}); fields *; limit ${gameIds.length};`)); const timings = []; const timeData = await getTimesToBeat(`where game_id = (${gameIds}); fields *; limit ${gameIds.length};`); @@ -56,17 +58,32 @@ module.exports = { return interaction.editReply({ embeds: [embed] }); } - for (let i = 0; i < timeData.length; i++) - { - if (timeData[i]) + let average; + let desc; + + if (!showmissingOption) { + for (let i = 0; i < timeData.length; i++) { - if (timeData[i].normally) { timings.push(timeData[i].normally / 3600); } - else if (timeData[i].hastily) { timings.push(timeData[i].hastily / 3600); } + if (timeData[i]) + { + if (timeData[i].normally) { timings.push(timeData[i].normally / 3600); } + else if (timeData[i].hastily) { timings.push(timeData[i].hastily / 3600); } + } } + + average = Math.round(timings.reduce((sum, num) => sum + num, 0)); + desc = `${user.displayName} has spent an estimated **${average} hours** beating games for the 100 games challenge *(${timings.length} of ${beatenGamesDatabaseEntries.length} included)*. `; + } else { + for (let i = 0; i < timeData.length; i++) + { + if (timeData[i].normally || timeData[i].hastily) + { + beatGameIGDBEntries = beatGameIGDBEntries.filter(item => item.id !== timeData[i].game_id); + } + } + desc = beatGameIGDBEntries.map(item => `[${item.name}](<${item.url}>)`).join('\n'); } - const average = Math.round(timings.reduce((sum, num) => sum + num, 0)); - const desc = `${user.displayName} has spent an estimated **${average} hours** beating games for the 100 games challenge *(${timings.length} of ${beatenGamesDatabaseEntries.length} included)*. `; const embed = new EmbedBuilder() .setColor(0x6441a5)