Fix multidrop not handling https:// links correctly

This commit is contained in:
Ethan Lane 2025-05-21 15:28:25 +01:00
parent 62bcd6914c
commit 9d59eedf14
2 changed files with 23 additions and 8 deletions

View file

@ -98,10 +98,18 @@ export default class Multidrop extends ButtonEvent {
await interaction.deferUpdate(); await interaction.deferUpdate();
try { try {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); const files = [];
const imageFileName = randomCard.card.path.split("/").pop()!; 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 inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0; const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -112,7 +120,7 @@ export default class Multidrop extends ButtonEvent {
await interaction.editReply({ await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: files,
components: [ row ], components: [ row ],
}); });
} catch (e) { } catch (e) {

View file

@ -62,10 +62,17 @@ export default class Multidrop extends Command {
await interaction.deferReply(); await interaction.deferReply();
try { try {
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path)); const files = [];
const imageFileName = randomCard.card.path.split("/").pop()!; 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 inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0; const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -76,7 +83,7 @@ export default class Multidrop extends Command {
await interaction.editReply({ await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: files,
components: [ row ], components: [ row ],
}); });
} catch (e) { } catch (e) {