From 1fd0e01704311f698b65f87a64784a5873e01758 Mon Sep 17 00:00:00 2001 From: MrlolDev Date: Sat, 23 Dec 2023 14:32:32 +0100 Subject: [PATCH] fix --- src/bot/commands/premium.ts | 1 - src/bot/utils/conversations.ts | 1 - src/bot/utils/db.ts | 4 ++-- src/bot/utils/premium.ts | 34 ++++++++++++++++++++-------------- src/bot/utils/settings.ts | 6 ++++-- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/bot/commands/premium.ts b/src/bot/commands/premium.ts index 2682a3e..6caaea6 100644 --- a/src/bot/commands/premium.ts +++ b/src/bot/commands/premium.ts @@ -24,7 +24,6 @@ async function buildInfo(bot: Bot, userId: BigString, guildId?: BigString): Prom content: "You don't have any premium plan or subscription.", }; const premiumInfo = await premium(environment); - console.log(premiumInfo); const embed = await generatePremiumEmbed({ environment: environment, premiumSelection: premiumInfo, diff --git a/src/bot/utils/conversations.ts b/src/bot/utils/conversations.ts index 7be3e0e..d6db597 100644 --- a/src/bot/utils/conversations.ts +++ b/src/bot/utils/conversations.ts @@ -55,7 +55,6 @@ export async function getConversation(userId: string, modelName: string) { // get the last 10 messages } - return conversation; } diff --git a/src/bot/utils/db.ts b/src/bot/utils/db.ts index bb9f130..c182f9f 100644 --- a/src/bot/utils/db.ts +++ b/src/bot/utils/db.ts @@ -191,12 +191,12 @@ export async function premium(env: Environment): Promise<{ location: "user" | "guild"; } | null> { /* In which order to use the plans in */ - const locationPriority: "guild" | "user" = (await getSettingsValue(env.user, "premium:location_priority")) as "guild" | "user"; + const locationPriority: "guild" | "user" = (await getSettingsValue(env.user, "premium:locationPriority")) as "guild" | "user"; /* Whether to prefer the Premium of the guild or user itself */ const typePriority: "plan" | "subscription" = (await getSettingsValue( env.guild ? env[locationPriority]! : env.user, - "premium:type_priority", + "premium:typePriority", )) as "plan" | "subscription"; const checks: Record boolean> = { diff --git a/src/bot/utils/premium.ts b/src/bot/utils/premium.ts index 3ea00be..3ebe192 100644 --- a/src/bot/utils/premium.ts +++ b/src/bot/utils/premium.ts @@ -70,8 +70,9 @@ export async function generatePremiumEmbed(premiumInfo: { for (const expense of user.plan.expenses) { if (expensesFields.length >= 10) break; expensesFields.push({ - name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model - }\` - $${expense.used?.toFixed(5) ?? "0"}`, + name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model}\` - $${ + expense.used?.toFixed(5) ?? "0" + }`, value: ``, }); } @@ -79,8 +80,9 @@ export async function generatePremiumEmbed(premiumInfo: { for (const expense of guild.plan.expenses) { if (expensesFields.length >= 10) break; expensesFields.push({ - name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model - }\` - $${expense.used?.toFixed(5) ?? "0"}`, + name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model}\` - $${ + expense.used?.toFixed(5) ?? "0" + }`, value: ``, }); } @@ -97,8 +99,9 @@ export async function generatePremiumEmbed(premiumInfo: { for (const charge of user.plan.history) { if (chargesFields.length >= 10) break; chargesFields.push({ - name: `${charge.type.slice(0, 1).toUpperCase()}${charge.type.slice(1)} ${charge.gateway ? `- using \`${charge.gateway}\`` : "" - }`, + name: `${charge.type.slice(0, 1).toUpperCase()}${charge.type.slice(1)} ${ + charge.gateway ? `- using \`${charge.gateway}\`` : "" + }`, value: `$${charge.amount?.toFixed(2) ?? "0"} - `, }); } @@ -106,8 +109,9 @@ export async function generatePremiumEmbed(premiumInfo: { for (const charge of guild.plan.history) { if (chargesFields.length >= 10) break; chargesFields.push({ - name: `${charge.type.slice(0, 1).toUpperCase()}${charge.type.slice(1)} ${charge.gateway ? `- using \`${charge.gateway}\`` : "" - }`, + name: `${charge.type.slice(0, 1).toUpperCase()}${charge.type.slice(1)} ${ + charge.gateway ? `- using \`${charge.gateway}\`` : "" + }`, value: `$${charge.amount?.toFixed(2)} - `, }); } @@ -123,11 +127,13 @@ export async function generatePremiumEmbed(premiumInfo: { // LAST EMBED let description = ""; if (premiumInfo.premiumSelection.location === "user" && user.plan) { - description = `**$${user.plan?.used?.toFixed(2)}**\`${generateProgressBar(user.plan.total, user.plan.used)}\`**$${user.plan?.total - }**`; + description = `**$${user.plan?.used?.toFixed(2)}**\`${generateProgressBar(user.plan.total, user.plan.used)}\`**$${ + user.plan?.total + }**`; } else if (premiumInfo.premiumSelection.location === "guild" && guild?.plan) { - description = `**$${guild.plan?.used?.toFixed(2)}**\`${generateProgressBar(guild.plan.total, guild.plan.used)}\`**$${guild.plan?.total - }**`; + description = `**$${guild.plan?.used?.toFixed(2)}**\`${generateProgressBar(guild.plan.total, guild.plan.used)}\`**$${ + guild.plan?.total + }**`; } embeds.push({ title: "Your pay-as-you-go plan 📊", @@ -227,7 +233,7 @@ export async function chargePlan(cost: number, environment: Environment, type: " total: environment.user.plan.total, history: environment.user.plan.history ?? [], expenses: [ - ...environment.user.plan.expenses ?? [], + ...(environment.user.plan.expenses ?? []), { data: { model, @@ -247,7 +253,7 @@ export async function chargePlan(cost: number, environment: Environment, type: " total: environment.guild.plan.total, history: environment.guild.plan.history ?? [], expenses: [ - ...environment.guild.plan.expenses ?? [], + ...(environment.guild.plan.expenses ?? []), { data: { model, diff --git a/src/bot/utils/settings.ts b/src/bot/utils/settings.ts index 0b740dc..3bfd9b8 100644 --- a/src/bot/utils/settings.ts +++ b/src/bot/utils/settings.ts @@ -30,8 +30,8 @@ function key2data(key: string) { return { collection, id }; } -export type EnabledSectionsTypes = "chat" | "image" | "premium" | string; -export const EnabledSections: Array = ["chat", "image", "general"]; +export type EnabledSectionsTypes = "general" | "chat" | "image" | "premium" | string; +export const EnabledSections: Array = ["chat", "image", "general", "premium"]; export async function generateSections(pageName: EnabledSectionsTypes, env: Environment): Promise { let message: null | CreateMessageOptions = null; const user = env.user; @@ -277,6 +277,7 @@ export function getMetadata( value: "subscription", }, ], + enabled: true, }; case "premium:locationPriority": return { @@ -295,6 +296,7 @@ export function getMetadata( value: "user", }, ], + enabled: true, }; default: return {