Burn: Added card burning for notes and gems

This commit is contained in:
2022-09-26 16:09:23 +02:00
parent bbbcaaaf29
commit 16bb46403b
9 changed files with 183 additions and 30 deletions

62
commands/burn.js Normal file
View File

@@ -0,0 +1,62 @@
const { SlashCommandBuilder, AttachmentBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require("discord.js");
const { Card, User, Band, Character } = require("../models");
const { QUALITY_VALUES, QUALITY_NAMES, CURRENCY_SYMBOLS } = require("../config/constants");
const { UserUtils } = require("../util");
const fs = require("fs");
const edit = require("./edit");
//fetch all cards owned by the user and list them
module.exports = {
data: new SlashCommandBuilder()
.setName("burn")
.setDescription("Burn a specific card")
.addStringOption((option) =>
option
.setName("id")
.setDescription("Card identifier")
.setRequired(true)
.setAutocomplete(true)
),
async execute(interaction) {
await interaction.deferReply();
let card = await Card.findOne({
where: {
identifier: interaction.options.getString("id")
},
include: [
{ model: Character, include: [{ model: Band }] },
{ model: User}
]
});
if (card === null) {
interaction.editReply({ content: "Card not found" });
return;
}
if (card.User.discordId !== interaction.user.id) {
interaction.editReply({ content: "You do not own this card" });
return;
}
if (card.burned) {
interaction.editReply({ content: "This card is already burned" });
return;
}
const embed = new EmbedBuilder()
.setTitle(`${interaction.member.displayName} burned ${card.identifier}`)
.setDescription(`+${QUALITY_VALUES[card.quality].value} ${CURRENCY_SYMBOLS[QUALITY_VALUES[card.quality].type]}`)
.addFields(
{ name: `${card.Character.name}`, value: `${card.Character.Band.name}` },
{ name: 'Print Number', value: `${card.printNr}`, inline: true },
{ name: 'Quality', value: `${QUALITY_NAMES[card.quality]}`, inline: true }
)
.setColor(0xFF0000)
.setFooter({ text: `${card.identifier}`, iconURL: 'https://cdn.discordapp.com/attachments/856904078754971658/1017431187234508820/fp.png' })
.setTimestamp(card.createdAt);
let user = await UserUtils.getUserByDiscordId(interaction.user.id);
await user.addCurrency(QUALITY_VALUES[card.quality].value, QUALITY_VALUES[card.quality].type, `burned ${card.identifier}`);
await card.update({ burned: true });
const message = await interaction.editReply({ embeds: [embed], fetchReply: true });
}
}

View File

@@ -89,7 +89,8 @@ module.exports = {
if (group) {
cards = await Card.findAndCountAll({
where: {
userId: user.id
userId: user.id,
burned: false
},
group: ["characterId"],
attributes: ["characterId", [Card.sequelize.fn("COUNT", "characterId"), "count"]],
@@ -104,7 +105,8 @@ module.exports = {
} else {
cards = await Card.findAndCountAll({
where: {
userId: user.id
userId: user.id,
burned: false
},
limit: pageSize,
offset: offset,

View File

@@ -51,7 +51,7 @@ module.exports = {
let slots = ['slotOne', 'slotTwo', 'slotThree', 'slotFour'];
let renderedCards = [];
for (slot of slots) {
let card = await Card.findOne({ where: { id: profile[slot] }});
let card = await Card.findOne({ where: { id: profile[slot], burned: false } });
if (card) {
let cardImage = await Rendering.renderCard(card);
renderedCards.push(cardImage);

View File

@@ -1,6 +1,6 @@
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { UserUtils } = require('../util');
const { QUALITY, QUALITY_NAMES } = require('../config/constants');
const { CURRENCY_SYMBOLS, QUALITY_NAMES } = require('../config/constants');
module.exports = {
data: new SlashCommandBuilder()
.setName("stats")
@@ -22,7 +22,15 @@ module.exports = {
let qualityCount = Array(6).fill(0);
let qualities = Object.values(QUALITY_NAMES);
let totalCards = 0;
let burnedCards = 0;
for (card of userCards.rows) {
if (card.burned) {
burnedCards++;
continue;
}
totalCards++;
qualityCount[card.quality-1]++;
}
@@ -33,7 +41,7 @@ module.exports = {
let embed = new EmbedBuilder()
.setTitle(`${discordUser.username}'s Stats`)
.addFields(
{ name: "Cards owned", value: `${qualities.join('\n')}\n${userCards.count} total`, inline: true },
{ name: "Cards owned", value: `${qualities.join('\n')}\n${totalCards} total - ${burnedCards} burned`, inline: true },
{ name: "Level", value: `${level.currentLevel}`, inline: true },
{ name: "Progress", value: `${level.currentExperience} / ${level.nextLevelExperience}\n${level.remaining} XP remaining`, inline: true },
{ name: "Registered since", value: `${registrationDate}`, inline: true }

View File

@@ -92,7 +92,10 @@ module.exports = {
.setColor(0x00ff00)
.setFooter({ text: `${card.identifier}`, iconURL: 'https://cdn.discordapp.com/attachments/856904078754971658/1017431187234508820/fp.png' })
.setTimestamp(card.createdAt);
if (card.burned) {
embed.setColor(0xff0000);
embed.addFields({ name: "Burned", value: "This card has been burned" });
}
const message = await interaction.editReply({ embeds: [embed], files: [cardImage], fetchReply: true });
},