From f38e6b8592adc5f5afdf38f35c46cae146605c2a Mon Sep 17 00:00:00 2001 From: Nathaniel Moschkin Date: Thu, 2 Nov 2023 23:21:44 -0400 Subject: [PATCH] Calculate and show expiration dates for quipment --- src/commands/quip.ts | 23 +++++++++++++++++++++-- src/datacore/player.ts | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/commands/quip.ts b/src/commands/quip.ts index dad3a94..f89b52e 100644 --- a/src/commands/quip.ts +++ b/src/commands/quip.ts @@ -31,10 +31,14 @@ async function asyncHandler( let user = await userFromMessage(message); let settings = user?.profiles[0] ? await loadProfile(user.profiles[0].dbid) : null; let profile = user?.profiles[0] ? loadFullProfile(user.profiles[0].dbid) : null; + let dnum = 0; if (!user || !profile) { sendAndCache(message, "Sorry, I couldn't find an associated profile for your user.") return; } + else { + dnum = (user.profiles[0].updatedAt as Date).getTime() / 1000; + } if (crewman?.length) { crewman = crewman.toLowerCase().trim(); } @@ -63,6 +67,9 @@ async function asyncHandler( return crew.symbol === crew.symbol }) as Definitions.BotCrew; crew = JSON.parse(JSON.stringify(crew)); + if (dnum) + crew.kwipment_expirations = (crew.kwipment_expiration.map(kw => new Date((dnum+kw[1]) * 1000))?.filter(chk => !!chk) ?? []) as Date[]; + crew.name = matched?.name ?? crew.name; crew.bigbook_tier = matched?.bigbook_tier; crew.date_added = new Date(crew.date_added); @@ -123,9 +130,12 @@ async function asyncHandler( if (can.kwipment_items?.length) { if (!!crewman) { embeds.push(embed); + let e = 0; for (let quip of can.kwipment_items) { let b = getItemBonuses(quip as EquipmentItem).bonuses as Definitions.Skills; - + let exp = (can.kwipment_expirations && can.kwipment_expiration.length > e) ? toTimestamp(can.kwipment_expirations[e]) : "N/A"; + e++; + embed = new EmbedBuilder() .setTitle(`${quip.name}`) .setDescription(quip.flavor) @@ -147,6 +157,11 @@ async function asyncHandler( value: `${quip.duration} h`, inline: true }, + { + name: "Expires On", + value: `${exp}`, + inline: true + }, { name: "Equippable By", value: `${rarityLabels[(quip.max_rarity_requirement ?? 1) - 1]} crew`, @@ -163,12 +178,16 @@ async function asyncHandler( } } else { + let e = 0; for (let quip of can.kwipment_items) { + let exp = (can.kwipment_expirations && can.kwipment_expiration.length > e) ? toTimestamp(can.kwipment_expirations[e]) : "N/A"; + e++; + let b = getItemBonuses(quip as EquipmentItem).bonuses as Definitions.Skills; embed = embed.addFields({ name: quip.name, - value: ((quip.rarity ? '⭐'.repeat(quip.rarity ?? 0) : '')) + formatSkillsStatsWithEmotes(message, b) + `\nDuration: ${quip.duration} h` + + value: ((quip.rarity ? '⭐'.repeat(quip.rarity ?? 0) : '')) + formatSkillsStatsWithEmotes(message, b) + `\nDuration: ${quip.duration} h (Expires on ${exp})` + ((!!quip.traits_requirement?.length) ? `\nTraits: ${quip.traits_requirement?.map(t => appelate(t)).join(` ${quip.traits_requirement_operator} `)}` : '') + `\nEquippable by ${rarityLabels[(quip.max_rarity_requirement ?? 1) - 1]} crew` diff --git a/src/datacore/player.ts b/src/datacore/player.ts index 1237922..d0725d8 100644 --- a/src/datacore/player.ts +++ b/src/datacore/player.ts @@ -452,8 +452,9 @@ export interface Player { equipment: number[][] | number[] kwipment: number[][]; - kwipment_expiration: number[]; + kwipment_expiration: number[][]; kwipment_items?: Definitions.Item[]; + kwipment_expirations?: Date[]; q_bits: number icon: Icon