From 9d59eedf14c8104d70960fe68e60a0b548f8ce75 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 21 May 2025 15:28:25 +0100 Subject: [PATCH] Fix multidrop not handling https:// links correctly --- src/buttonEvents/Multidrop.ts | 16 ++++++++++++---- src/commands/multidrop.ts | 15 +++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/buttonEvents/Multidrop.ts b/src/buttonEvents/Multidrop.ts index e6ea7c2..e88d6ef 100644 --- a/src/buttonEvents/Multidrop.ts +++ b/src/buttonEvents/Multidrop.ts @@ -98,10 +98,18 @@ export default class Multidrop extends ButtonEvent { await interaction.deferUpdate(); try { - const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); - const imageFileName = randomCard.card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; + + if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); + imageFileName = randomCard.card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); + } - const attachment = new AttachmentBuilder(image, { name: imageFileName }); const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -112,7 +120,7 @@ export default class Multidrop extends ButtonEvent { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); } catch (e) { diff --git a/src/commands/multidrop.ts b/src/commands/multidrop.ts index aa42686..82d19fe 100644 --- a/src/commands/multidrop.ts +++ b/src/commands/multidrop.ts @@ -62,10 +62,17 @@ export default class Multidrop extends Command { await interaction.deferReply(); try { - const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); - const imageFileName = randomCard.card.path.split("/").pop()!; + const files = []; + let imageFileName = ""; - const attachment = new AttachmentBuilder(image, { name: imageFileName }); + if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) { + const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); + imageFileName = randomCard.card.path.split("/").pop()!; + + const attachment = new AttachmentBuilder(image, { name: imageFileName }); + + files.push(attachment); + } const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id); const quantityClaimed = inventory ? inventory.Quantity : 0; @@ -76,7 +83,7 @@ export default class Multidrop extends Command { await interaction.editReply({ embeds: [ embed ], - files: [ attachment ], + files: files, components: [ row ], }); } catch (e) {