Fix multidrop not handling externally hosted images correctly (#447)
All checks were successful
Test / build (push) Successful in 48s
All checks were successful
Test / build (push) Successful in 48s
- Fix multidrop command not handling externally hosted images correctly - It was trying to find the `https://` link in the file system, which it couldn't find - Fixed by copying existing logic from the drop command into the multidrop command #442 Reviewed-on: #447 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
62bcd6914c
commit
f2c949c78a
4 changed files with 49 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
13
tests/buttonEvents/Multidrop.test.ts
Normal file
13
tests/buttonEvents/Multidrop.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
describe("execute", () => {
|
||||
describe("GIVEN randomCard image is hosted locally", () => {
|
||||
test.todo("EXPECT image to be uploaded directly");
|
||||
});
|
||||
|
||||
describe("GIVEN randomCard image is hosted via http", () => {
|
||||
test.todo("EXPECT image link to be directly added to embed");
|
||||
});
|
||||
|
||||
describe("GIVEN randomCard image is hosted via https", () => {
|
||||
test.todo("EXPECT image link to be directly added to embed");
|
||||
});
|
||||
});
|
13
tests/commands/multidrop.test.ts
Normal file
13
tests/commands/multidrop.test.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
describe("execute", () => {
|
||||
describe("GIVEN randomCard image is hosted locally", () => {
|
||||
test.todo("EXPECT image to be uploaded directly");
|
||||
});
|
||||
|
||||
describe("GIVEN randomCard image is hosted via http", () => {
|
||||
test.todo("EXPECT image link to be directly added to embed");
|
||||
});
|
||||
|
||||
describe("GIVEN randomCard image is hosted via https", () => {
|
||||
test.todo("EXPECT image link to be directly added to embed");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue