Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MrlolDev committed Dec 23, 2023
1 parent f57d150 commit 1fd0e01
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/bot/commands/premium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/bot/utils/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export async function getConversation(userId: string, modelName: string) {
// get the last 10 messages
}


return conversation;
}

Expand Down
4 changes: 2 additions & 2 deletions src/bot/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof typePriority, (entry: Guild | User) => boolean> = {
Expand Down
34 changes: 20 additions & 14 deletions src/bot/utils/premium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,19 @@ 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: `<t:${Math.floor(expense.time / 1000)}:R>`,
});
}
} else if (premiumInfo.premiumSelection.location === "guild" && guild?.plan) {
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: `<t:${Math.floor(expense.time / 1000)}>`,
});
}
Expand All @@ -97,17 +99,19 @@ 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"} - <t:${Math.floor(charge.time / 1000)}>`,
});
}
} else if (premiumInfo.premiumSelection.location === "guild" && guild?.plan) {
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)} - <t:${Math.floor(charge.time / 1000)}>`,
});
}
Expand All @@ -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 📊",
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/bot/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function key2data(key: string) {
return { collection, id };
}

export type EnabledSectionsTypes = "chat" | "image" | "premium" | string;
export const EnabledSections: Array<EnabledSectionsTypes> = ["chat", "image", "general"];
export type EnabledSectionsTypes = "general" | "chat" | "image" | "premium" | string;
export const EnabledSections: Array<EnabledSectionsTypes> = ["chat", "image", "general", "premium"];
export async function generateSections(pageName: EnabledSectionsTypes, env: Environment): Promise<CreateMessageOptions | null> {
let message: null | CreateMessageOptions = null;
const user = env.user;
Expand Down Expand Up @@ -277,6 +277,7 @@ export function getMetadata(
value: "subscription",
},
],
enabled: true,
};
case "premium:locationPriority":
return {
Expand All @@ -295,6 +296,7 @@ export function getMetadata(
value: "user",
},
],
enabled: true,
};
default:
return {
Expand Down

0 comments on commit 1fd0e01

Please sign in to comment.