From fa786d66fe951c5f58a8aefebb729d513da09a87 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 14 Feb 2024 19:11:28 +0000 Subject: [PATCH] Check if coverart exists before attaching to embed --- commands/100-games/beatGame.js | 7 +++++-- commands/100-games/deletebeatengame.js | 7 +++++-- commands/100-games/deleteplannedgame.js | 7 +++++-- commands/100-games/deleteplayinggame.js | 7 +++++-- commands/100-games/planGame.js | 7 +++++-- commands/100-games/plannedGames.js | 2 +- commands/100-games/recentbeat.js | 15 ++++++++++----- commands/100-games/startplaying.js | 7 +++++-- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/commands/100-games/beatGame.js b/commands/100-games/beatGame.js index 3fcb37b..e2e151c 100644 --- a/commands/100-games/beatGame.js +++ b/commands/100-games/beatGame.js @@ -49,17 +49,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0xFFD700) .setAuthor({ name: `${interaction.user.displayName} beat a new game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name} beaten!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + await interaction.followUp({ embeds: [embed] }); if (beatNum == 100) { diff --git a/commands/100-games/deletebeatengame.js b/commands/100-games/deletebeatengame.js index 1000814..c1af52b 100644 --- a/commands/100-games/deletebeatengame.js +++ b/commands/100-games/deletebeatengame.js @@ -33,17 +33,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0xFF0000) .setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name} deleted!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + return interaction.followUp({ embeds: [embed] }); } diff --git a/commands/100-games/deleteplannedgame.js b/commands/100-games/deleteplannedgame.js index c68694d..588294c 100644 --- a/commands/100-games/deleteplannedgame.js +++ b/commands/100-games/deleteplannedgame.js @@ -33,17 +33,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0xFF0000) .setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name} deleted!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + return interaction.followUp({ embeds: [embed] }); } diff --git a/commands/100-games/deleteplayinggame.js b/commands/100-games/deleteplayinggame.js index 11cb11e..7f5a93a 100644 --- a/commands/100-games/deleteplayinggame.js +++ b/commands/100-games/deleteplayinggame.js @@ -33,17 +33,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0xFF0000) .setAuthor({ name: `${interaction.user.displayName} deleted a game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name} deleted!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + return interaction.followUp({ embeds: [embed] }); } diff --git a/commands/100-games/planGame.js b/commands/100-games/planGame.js index cc91cb2..ed37c7e 100644 --- a/commands/100-games/planGame.js +++ b/commands/100-games/planGame.js @@ -43,17 +43,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0x43ABEC) .setAuthor({ name: `${interaction.user.displayName} is planning to beat a game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name}!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + await interaction.followUp({ embeds: [embed] }); }, }; \ No newline at end of file diff --git a/commands/100-games/plannedGames.js b/commands/100-games/plannedGames.js index 61e8f8a..2e3f2a3 100644 --- a/commands/100-games/plannedGames.js +++ b/commands/100-games/plannedGames.js @@ -36,7 +36,7 @@ module.exports = { const embed = new EmbedBuilder() .setColor(0x6441a5) .setAuthor({ name: `${user.displayName}`, iconURL: user.avatarURL() }) - .setTitle(`${user.displayName}'s planned games to play`) + .setTitle(`${user.displayName}'s planned games`) .setDescription(desc) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); diff --git a/commands/100-games/recentbeat.js b/commands/100-games/recentbeat.js index 3fa8ea4..57b932e 100644 --- a/commands/100-games/recentbeat.js +++ b/commands/100-games/recentbeat.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const { getCoverURL, getGameJson } = require('../../igdbHelperFunctions.js'); -const { getUserRegistration, getRecentBeatenGameEntry, getBeatenGameCount } = require('../../databaseHelperFunctions.js'); +const { getUserRegistration, getRecentBeatenGameEntry, getBeatenGameCount, getPlanningGameCount, getPlayingGameCount } = require('../../databaseHelperFunctions.js'); module.exports = { data: new SlashCommandBuilder() @@ -26,17 +26,22 @@ module.exports = { if (!res) return interaction.reply({ content: 'No game found.', ephemeral: true }); const game = res[0]; - const coverUrl = await getCoverURL(game.cover); - const num = await getBeatenGameCount(userDatabaseEntry); + const beatNum = await getBeatenGameCount(userDatabaseEntry); + const planNum = await getPlanningGameCount(userDatabaseEntry); + const playNum = await getPlayingGameCount(userDatabaseEntry); const embed = new EmbedBuilder() .setColor(0xFFD700) .setAuthor({ name: `${user.displayName}'s most recent beat game!`, iconURL: user.avatarURL() }) .setTitle(game.name) - .setThumbnail(`${coverUrl}`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp() - .setDescription(`${interaction.user.displayName} has beaten ${num} games, they have ${100 - num} games remaining.`); + .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`); + + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } return interaction.reply({ embeds: [embed] }); }, diff --git a/commands/100-games/startplaying.js b/commands/100-games/startplaying.js index af87361..fbb8fc8 100644 --- a/commands/100-games/startplaying.js +++ b/commands/100-games/startplaying.js @@ -46,17 +46,20 @@ module.exports = { const beatNum = await getBeatenGameCount(userDatabaseEntry); const planNum = await getPlanningGameCount(userDatabaseEntry); const playNum = await getPlayingGameCount(userDatabaseEntry); - const coverUrl = await getCoverURL(game.cover); const embed = new EmbedBuilder() .setColor(0x00C921) .setAuthor({ name: `${interaction.user.displayName} has started playing a new game!`, iconURL: interaction.user.avatarURL() }) .setTitle(`${game.name}!`) - .setThumbnail(`${coverUrl}`) .setDescription(`${interaction.user.displayName} has ${planNum} games planned, they are playing ${playNum} games, they have beaten ${beatNum} games, they have ${100 - beatNum} games remaining.`) .setFooter({ text: 'The Ochulus • 100 Games Challenge', iconURL: interaction.client.user.avatarURL() }) .setTimestamp(); + if (game.cover) { + const coverUrl = await getCoverURL(game.cover); + embed.setThumbnail(`${coverUrl}`); + } + await interaction.followUp({ embeds: [embed] }); }, }; \ No newline at end of file