From b8623398a61d2b51b4bc31dd5091dbd665e2abad Mon Sep 17 00:00:00 2001
From: Ethan Lane <ethan@vylpes.com>
Date: Sun, 19 Jan 2025 15:07:40 +0000
Subject: [PATCH 1/3] Implement ability to add images in the drop via an
 external url

---
 src/buttonEvents/Reroll.ts            | 15 +++++++++++----
 src/commands/drop.ts                  | 15 +++++++++++----
 src/commands/stage/dropnumber.ts      | 20 ++++++++++----------
 src/commands/stage/droprarity.ts      | 22 ++++++++++------------
 src/commands/view.ts                  | 20 +++++++++-----------
 src/helpers/CardDropHelperMetadata.ts | 10 ++++++++--
 6 files changed, 59 insertions(+), 43 deletions(-)

diff --git a/src/buttonEvents/Reroll.ts b/src/buttonEvents/Reroll.ts
index 12578db..dc9622a 100644
--- a/src/buttonEvents/Reroll.ts
+++ b/src/buttonEvents/Reroll.ts
@@ -51,10 +51,17 @@ export default class Reroll extends ButtonEvent {
         try {
             AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
 
-            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;
@@ -67,7 +74,7 @@ export default class Reroll extends ButtonEvent {
 
             await interaction.editReply({
                 embeds: [ embed ],
-                files: [ attachment ],
+                files: files,
                 components: [ row ],
             });
 
diff --git a/src/commands/drop.ts b/src/commands/drop.ts
index 6f74d3a..66558e3 100644
--- a/src/commands/drop.ts
+++ b/src/commands/drop.ts
@@ -59,10 +59,17 @@ export default class Drop 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;
@@ -75,7 +82,7 @@ export default class Drop extends Command {
 
             await interaction.editReply({
                 embeds: [ embed ],
-                files: [ attachment ],
+                files: files,
                 components: [ row ],
             });
 
diff --git a/src/commands/stage/dropnumber.ts b/src/commands/stage/dropnumber.ts
index 0642327..750210d 100644
--- a/src/commands/stage/dropnumber.ts
+++ b/src/commands/stage/dropnumber.ts
@@ -43,20 +43,20 @@ export default class Dropnumber extends Command {
         const series = CoreClient.Cards
             .find(x => x.cards.includes(card))!;
 
-        let image: Buffer;
-        const imageFileName = card.path.split("/").pop()!;
+        const files = [];
+        let imageFileName = "";
 
-        try {
-            image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
-        } catch {
-            await interaction.reply(`Unable to fetch image for card ${card.id}`);
-            return;
+        if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
+            const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
+            imageFileName = card.path.split("/").pop()!;
+
+            const attachment = new AttachmentBuilder(image, { name: imageFileName });
+
+            files.push(attachment);
         }
 
         await interaction.deferReply();
 
-        const attachment = new AttachmentBuilder(image, { name: imageFileName });
-
         const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
         const quantityClaimed = inventory ? inventory.Quantity : 0;
 
@@ -69,7 +69,7 @@ export default class Dropnumber extends Command {
         try {
             await interaction.editReply({
                 embeds: [ embed ],
-                files: [ attachment ],
+                files: files,
                 components: [ row ],
             });
         } catch (e) {
diff --git a/src/commands/stage/droprarity.ts b/src/commands/stage/droprarity.ts
index be0a62d..0e95db0 100644
--- a/src/commands/stage/droprarity.ts
+++ b/src/commands/stage/droprarity.ts
@@ -46,20 +46,18 @@ export default class Droprarity extends Command {
             return;
         }
 
-        let image: Buffer;
-        const imageFileName = card.card.path.split("/").pop()!;
+        const files = [];
+        let imageFileName = "";
 
-        try {
-            image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
-        } catch {
-            await interaction.reply(`Unable to fetch image for card ${card.card.id}`);
-            return;
+        if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
+            const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
+            imageFileName = card.card.path.split("/").pop()!;
+
+            const attachment = new AttachmentBuilder(image, { name: imageFileName });
+
+            files.push(attachment);
         }
 
-        await interaction.deferReply();
-
-        const attachment = new AttachmentBuilder(image, { name: imageFileName });
-
         const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
         const quantityClaimed = inventory ? inventory.Quantity : 0;
 
@@ -72,7 +70,7 @@ export default class Droprarity extends Command {
         try {
             await interaction.editReply({
                 embeds: [ embed ],
-                files: [ attachment ],
+                files: files,
                 components: [ row ],
             });
         } catch (e) {
diff --git a/src/commands/view.ts b/src/commands/view.ts
index ce6f9cb..0e29db5 100644
--- a/src/commands/view.ts
+++ b/src/commands/view.ts
@@ -43,22 +43,20 @@ export default class View extends Command {
         const series = CoreClient.Cards
             .find(x => x.cards.includes(card))!;
 
-        let image: Buffer;
-        const imageFileName = card.path.split("/").pop()!;
+        const files = [];
+        let imageFileName = "";
 
-        try {
-            image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
-        } catch {
-            AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`);
+        if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
+            const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
+            imageFileName = card.path.split("/").pop()!;
 
-            await interaction.reply(`Unable to fetch image for card ${card.id}.`);
-            return;
+            const attachment = new AttachmentBuilder(image, { name: imageFileName });
+
+            files.push(attachment);
         }
 
         await interaction.deferReply();
 
-        const attachment = new AttachmentBuilder(image, { name: imageFileName });
-
         const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
         const quantityClaimed = inventory ? inventory.Quantity : 0;
 
@@ -67,7 +65,7 @@ export default class View extends Command {
         try {
             await interaction.editReply({
                 embeds: [ embed ],
-                files: [ attachment ],
+                files: files,
             });
         } catch (e) {
             AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`);
diff --git a/src/helpers/CardDropHelperMetadata.ts b/src/helpers/CardDropHelperMetadata.ts
index bc59e93..342f347 100644
--- a/src/helpers/CardDropHelperMetadata.ts
+++ b/src/helpers/CardDropHelperMetadata.ts
@@ -89,7 +89,7 @@ export default class CardDropHelperMetadata {
             const hexCode = Number("0x" + drop.card.colour);
 
             if (hexCode) {
-                colour = hexCode; 
+                colour = hexCode;
             } else {
                 AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`);
             }
@@ -97,12 +97,18 @@ export default class CardDropHelperMetadata {
             AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`);
         }
 
+        let imageUrl = `attachment://${imageFileName}`;
+
+        if (drop.card.path.startsWith("http://") || drop.card.path.startsWith("https://")) {
+            imageUrl = drop.card.path;
+        }
+
         const embed = new EmbedBuilder()
             .setTitle(drop.card.name)
             .setDescription(description)
             .setFooter({ text: `${CardRarityToString(drop.card.type)} ยท ${drop.card.id}` })
             .setColor(colour)
-            .setImage(`attachment://${imageFileName}`)
+            .setImage(imageUrl)
             .addFields([
                 {
                     name: "Claimed",

From c53e09f510fc5968ef6bff765d61c8bf730ed083 Mon Sep 17 00:00:00 2001
From: Ethan Lane <ethan@vylpes.com>
Date: Sun, 19 Jan 2025 15:09:17 +0000
Subject: [PATCH 2/3] 0.8.3

---
 .env.example | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.env.example b/.env.example
index 4515de6..44016d2 100644
--- a/.env.example
+++ b/.env.example
@@ -7,7 +7,7 @@
 # any secret values.
 
 BOT_TOKEN=
-BOT_VER=0.8.2
+BOT_VER=0.8.3
 BOT_AUTHOR=Vylpes
 BOT_OWNERID=147392775707426816
 BOT_CLIENTID=682942374040961060

From ce0bc15c029d9b37138a60cae4b2fe9db9f4e719 Mon Sep 17 00:00:00 2001
From: Ethan Lane <ethan@vylpes.com>
Date: Sun, 19 Jan 2025 15:11:41 +0000
Subject: [PATCH 3/3] v0.8.3

---
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package.json b/package.json
index 69f3158..d7178df 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "card-drop",
-  "version": "0.8.2",
+  "version": "0.8.3",
   "main": "./dist/bot.js",
   "typings": "./dist",
   "scripts": {