From 498cfa1c18479c6abc9ef316c47ff7736a9e4566 Mon Sep 17 00:00:00 2001 From: Mara Date: Sun, 1 Dec 2024 19:47:46 +0100 Subject: [PATCH] fix: statistic not found when registering the first time a dice --- src/interactions/add/dice.ts | 3 --- src/utils/db.ts | 13 ++++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/interactions/add/dice.ts b/src/interactions/add/dice.ts index 47efca44..d9449904 100644 --- a/src/interactions/add/dice.ts +++ b/src/interactions/add/dice.ts @@ -8,7 +8,6 @@ import { editUserButtons, registerDmgButton } from "@utils/buttons"; import { getTemplateWithDB, getUserByEmbed, registerUser } from "@utils/db"; import { ensureEmbed, getEmbeds } from "@utils/parse"; import * as Djs from "discord.js"; -import { logger } from "../../logger"; /** * Interaction to add a new skill dice * @param interaction {Djs.ButtonInteraction} @@ -144,7 +143,6 @@ export async function registerDamageDice( } } const user = getUserByEmbed(interaction.message, ul, first); - logger.trace("user", user); if (!user) throw new Error(ul("error.user")); //mean that there is no embed value = evalStatsDice(value, user.stats); @@ -220,7 +218,6 @@ export async function registerDamageDice( const userEmbed = getEmbeds(ul, interaction.message ?? undefined, "user"); if (!userEmbed) throw new NoEmbed(); //mean that there is no embed const statsEmbed = getEmbeds(ul, interaction.message ?? undefined, "stats"); - logger.trace("stats", statsEmbed); const allEmbeds = [userEmbed]; if (statsEmbed) allEmbeds.push(statsEmbed); allEmbeds.push(diceEmbed); diff --git a/src/utils/db.ts b/src/utils/db.ts index 3aeb8c47..94774aba 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -273,14 +273,11 @@ export function getUserByEmbed( if (charNameFields && charNameFields.value !== "common.noSet") { user.userName = charNameFields.value; } - const templateStat = first - ? userEmbed.toJSON().fields - : getEmbeds(ul, message, "stats")?.toJSON()?.fields; + const statsFields = getEmbeds(ul, message, "stats")?.toJSON()?.fields; let stats: { [name: string]: number } | undefined = undefined; - if (templateStat) { + if (statsFields) { stats = {}; - for (const stat of templateStat) { - if (first && !stat.name.startsWith("✏")) continue; + for (const stat of statsFields) { const value = Number.parseInt(stat.value.removeBacktick(), 10); if (Number.isNaN(value)) { //it's a combinaison @@ -292,9 +289,7 @@ export function getUserByEmbed( } } user.stats = stats; - const damageFields = first - ? userEmbed.toJSON().fields - : getEmbeds(ul, message, "damage")?.toJSON()?.fields; + const damageFields = getEmbeds(ul, message, "damage")?.toJSON()?.fields; let templateDamage: { [name: string]: string } | undefined = undefined; if (damageFields) { templateDamage = {};