From 7a72be4e64391c8393c56786cd95e9066d19c680 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 13 Dec 2023 17:32:51 +0000 Subject: [PATCH] Add console log on drop command error --- src/buttonEvents/Reroll.ts | 36 ++++++++++++++---------------------- src/commands/drop.ts | 35 ++++++++++++++--------------------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts index 274c846..3b86e72 100644 --- a/src/buttonEvents/Reroll.ts +++ b/src/buttonEvents/Reroll.ts @@ -27,45 +27,37 @@ export default class Reroll extends ButtonEvent { return; } - let image: Buffer; - const imageFileName = randomCard.card.path.split("/").pop()!; - try { + let image: Buffer; + const imageFileName = randomCard.card.path.split("/").pop()!; + image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); - } catch { - await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`); - return; - } - await interaction.deferReply(); + await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); - const quantityClaimed = inventory ? inventory.Quantity : 0; + const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); + const quantityClaimed = inventory ? inventory.Quantity : 0; - const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); + const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); - const claimId = v4(); + const claimId = v4(); - const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); - try { await interaction.editReply({ embeds: [ embed ], files: [ attachment ], components: [ row ], }); + + CoreClient.ClaimId = claimId; + } catch (e) { console.error(e); - if (e instanceof DiscordAPIError) { - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`); - } else { - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`); - } + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`); } - - CoreClient.ClaimId = claimId; } } \ No newline at end of file diff --git a/src/commands/drop.ts b/src/commands/drop.ts index 9c6646a..5a8ccd9 100644 --- a/src/commands/drop.ts +++ b/src/commands/drop.ts @@ -35,45 +35,38 @@ export default class Drop extends Command { return; } - let image: Buffer; - const imageFileName = randomCard.card.path.split("/").pop()!; - try { + let image: Buffer; + const imageFileName = randomCard.card.path.split("/").pop()!; + image = readFileSync(path.join(process.cwd(), 'cards', randomCard.card.path)); - } catch { - await interaction.reply(`Unable to fetch image for card ${randomCard.card.id}`); - return; - } - await interaction.deferReply(); + await interaction.deferReply(); - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + const attachment = new AttachmentBuilder(image, { name: imageFileName }); - const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); - const quantityClaimed = inventory ? inventory.Quantity : 0; + const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); + const quantityClaimed = inventory ? inventory.Quantity : 0; - const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); + const embed = CardDropHelperMetadata.GenerateDropEmbed(randomCard, quantityClaimed, imageFileName); - const claimId = v4(); + const claimId = v4(); - const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); + const row = CardDropHelperMetadata.GenerateDropButtons(randomCard, claimId, interaction.user.id); - try { await interaction.editReply({ embeds: [ embed ], files: [ attachment ], components: [ row ], }); + + CoreClient.ClaimId = claimId; + } catch (e) { console.error(e); - if (e instanceof DiscordAPIError) { - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: ${e.code}`); - } else { - await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. Code: UNKNOWN`); - } + await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`); } - CoreClient.ClaimId = claimId; } } \ No newline at end of file