Update id command from merge
All checks were successful
Deploy To Stage / build (push) Successful in 46s
Deploy To Stage / deploy (push) Successful in 18s

This commit is contained in:
Ethan Lane 2025-01-19 15:19:28 +00:00
parent 7213703f66
commit 3e81f8ce1d

View file

@ -43,22 +43,20 @@ export default class Id extends Command {
const series = CoreClient.Cards const series = CoreClient.Cards
.find(x => x.cards.includes(card))!; .find(x => x.cards.includes(card))!;
let image: Buffer; const files = [];
const imageFileName = card.path.split("/").pop()!; let imageFileName = "";
try { if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path)); const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
} catch { imageFileName = card.path.split("/").pop()!;
AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`);
await interaction.reply(`Unable to fetch image for card ${card.id}.`); const attachment = new AttachmentBuilder(image, { name: imageFileName });
return;
files.push(attachment);
} }
await interaction.deferReply(); await interaction.deferReply();
const attachment = new AttachmentBuilder(image, { name: imageFileName });
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id); const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
const quantityClaimed = inventory ? inventory.Quantity : 0; const quantityClaimed = inventory ? inventory.Quantity : 0;
@ -67,7 +65,7 @@ export default class Id extends Command {
try { try {
await interaction.editReply({ await interaction.editReply({
embeds: [ embed ], embeds: [ embed ],
files: [ attachment ], files: files,
}); });
} catch (e) { } catch (e) {
AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`); AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`);