View: Add view embed

This commit is contained in:
2022-09-08 17:30:27 +02:00
parent 6ce583c8fb
commit ff879d179d

View File

@@ -1,5 +1,5 @@
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { Card, User, Character } = require("../models");
const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder } = require("discord.js");
const { Card, User, Band, Character } = require("../models");
const Rendering = require("../util/rendering");
//fetch all cards owned by the user and list them
@@ -20,7 +20,11 @@ module.exports = {
where: {
identifier: cardId
},
include: [Character]
include: [
{ model: Character, include:
[Band] },
User
]
});
if (!card) {
interaction.reply({
@@ -31,7 +35,39 @@ module.exports = {
}
let cardImage = await Rendering.renderCard(card);
const message = await interaction.editReply({ content: '', files: [new AttachmentBuilder(cardImage, { name: 'card.gif' })], fetchReply: true });
let attachment = new AttachmentBuilder(card);
//get base filename
let filename = cardImage.split("/").pop();
let description = "";
//Add a new line after every 4th (long) word or after a full stop
let words = card.Character.description.split(" ");
let count = 0;
for (let i = 0; i < words.length; i++) {
description += words[i] + " ";
if (words[i].length > 3) {
count++;
}
if (count >= 4 || words[i].endsWith(".")) {
description += "\n";
count = 0;
}
}
const embed = new EmbedBuilder()
.setTitle(`${card.Character.name}`)
.setDescription(description)
.setImage(`attachment://${filename}`)
.setThumbnail(card.Character.Band.imageURL)
.addFields(
{ name: "Owned by", value: `<@${card.User.discordId}>` },
{ name: "Band", value: `${card.Character.Band.name}` },
{ name: 'Print Number', value: `${card.printNr}`, inline: true },
{ name: 'Quality', value: `${card.quality}`, inline: true }
)
.setColor(0x00ff00)
.setFooter({ text: `${card.identifier}`, iconURL: 'https://cdn.discordapp.com/attachments/856904078754971658/1017431187234508820/fp.png' })
.setTimestamp(card.createdAt);
const message = await interaction.editReply({ embeds: [embed], files: [cardImage], fetchReply: true });
}
}