Implement ability to add images in the drop via an external url
All checks were successful
Test / build (push) Successful in 19s
All checks were successful
Test / build (push) Successful in 19s
This commit is contained in:
parent
d9d0243c3c
commit
b8623398a6
6 changed files with 59 additions and 43 deletions
|
@ -51,11 +51,18 @@ export default class Reroll extends ButtonEvent {
|
||||||
try {
|
try {
|
||||||
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
|
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
|
||||||
|
|
||||||
|
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));
|
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
||||||
const imageFileName = randomCard.card.path.split("/").pop()!;
|
imageFileName = randomCard.card.path.split("/").pop()!;
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
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;
|
||||||
|
|
||||||
|
@ -67,7 +74,7 @@ export default class Reroll extends ButtonEvent {
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: [ attachment ],
|
files: files,
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,18 @@ export default class Drop extends Command {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
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));
|
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
||||||
const imageFileName = randomCard.card.path.split("/").pop()!;
|
imageFileName = randomCard.card.path.split("/").pop()!;
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
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;
|
||||||
|
|
||||||
|
@ -75,7 +82,7 @@ export default class Drop extends Command {
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: [ attachment ],
|
files: files,
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -43,20 +43,20 @@ export default class Dropnumber 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()!;
|
||||||
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();
|
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;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ export default class Dropnumber extends Command {
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: [ attachment ],
|
files: files,
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -46,20 +46,18 @@ export default class Droprarity extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let image: Buffer;
|
const files = [];
|
||||||
const imageFileName = card.card.path.split("/").pop()!;
|
let imageFileName = "";
|
||||||
|
|
||||||
try {
|
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
|
||||||
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
||||||
} catch {
|
imageFileName = card.card.path.split("/").pop()!;
|
||||||
await interaction.reply(`Unable to fetch image for card ${card.card.id}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await interaction.deferReply();
|
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
|
files.push(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -72,7 +70,7 @@ export default class Droprarity extends Command {
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: [ attachment ],
|
files: files,
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -43,22 +43,20 @@ export default class View 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 View 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}`);
|
||||||
|
|
|
@ -97,12 +97,18 @@ export default class CardDropHelperMetadata {
|
||||||
AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`);
|
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()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(drop.card.name)
|
.setTitle(drop.card.name)
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` })
|
.setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` })
|
||||||
.setColor(colour)
|
.setColor(colour)
|
||||||
.setImage(`attachment://${imageFileName}`)
|
.setImage(imageUrl)
|
||||||
.addFields([
|
.addFields([
|
||||||
{
|
{
|
||||||
name: "Claimed",
|
name: "Claimed",
|
||||||
|
|
Loading…
Reference in a new issue