diff --git a/src/bot/commands/chat.ts b/src/bot/commands/chat.ts index 5dd5dd7..48795f4 100644 --- a/src/bot/commands/chat.ts +++ b/src/bot/commands/chat.ts @@ -99,8 +99,8 @@ async function buildInfo( let loadingIndicatorIndex = (await getSettingsValue(user, "general:loadingIndicator")) as number | string; if ( !loadingIndicatorIndex || - loadingIndicatorIndex == "default" || - (typeof loadingIndicatorIndex == "string" && parseInt(loadingIndicatorIndex) >= LOADING_INDICATORS.length) + loadingIndicatorIndex === "default" || + (typeof loadingIndicatorIndex === "string" && parseInt(loadingIndicatorIndex) >= LOADING_INDICATORS.length) ) { loadingIndicatorIndex = (await getDefaultValues("general:loadingIndicator")) as number; } @@ -170,8 +170,9 @@ async function buildInfo( lastUpdate = Date.now(); if (characters.length > 2000) { await edit({ - content: `<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${loadingIndicator.emoji.id - }>`, + content: `<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${ + loadingIndicator.emoji.id + }>`, // send result as a file files: [ { @@ -182,8 +183,9 @@ async function buildInfo( }); } else { await edit({ - content: `${data.result}<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${loadingIndicator.emoji.id - }>`, + content: `${data.result}<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${ + loadingIndicator.emoji.id + }>`, }); } } diff --git a/src/bot/commands/grant.ts b/src/bot/commands/grant.ts new file mode 100644 index 0000000..32281f9 --- /dev/null +++ b/src/bot/commands/grant.ts @@ -0,0 +1,25 @@ +import { NoCooldown, createCommand } from "../config/setup.js"; + +export default createCommand({ + body: { + name: "grant", + description: "View information & statistics about the bot", + options: [ + { + name: "plan", + type: "SubCommand", + description: "Customize the bot for yourself", + }, + { + name: "subscription", + type: "SubCommand", + description: "Customize the bot for the entire server", + }, + ], + }, + cooldown: NoCooldown, + pr: true, + interaction: async ({ interaction }) => { + await interaction.edit({}); + }, +}); diff --git a/src/bot/commands/index.ts b/src/bot/commands/index.ts index 8037d66..8865fed 100644 --- a/src/bot/commands/index.ts +++ b/src/bot/commands/index.ts @@ -1,8 +1,9 @@ import Bot from "./bot.js"; -import Imagine from "./imagine.js"; import Chat from "./chat.js"; +import grant from "./grant.js"; +import Imagine from "./imagine.js"; import Premium from "./premium.js"; -import Settings from "./settings.js"; import Reset from "./reset.js"; +import Settings from "./settings.js"; -export const commands = [Bot, Chat, Imagine, Premium, Settings, Reset]; +export const commands = [Bot, Chat, Imagine, Premium, Settings, Reset, grant]; diff --git a/src/bot/commands/translate.ts b/src/bot/commands/translate.ts new file mode 100644 index 0000000..d59a8ed --- /dev/null +++ b/src/bot/commands/translate.ts @@ -0,0 +1,17 @@ +import { BigString, Bot, ButtonComponent, CreateMessageOptions, MessageComponentTypes } from "@discordeno/bot"; +import config from "../../config.js"; +import { NoCooldown, buttonInfo, createCommand } from "../config/setup.js"; +import { gatewayConfig } from "../index.js"; +import { resetConversation } from "../utils/conversations.js"; +import { getDefaultValues, getSettingsValue } from "../utils/settings.js"; + +export default createCommand({ + body: { + name: "translate", + type: "Message", + description: "Translate a message", + }, + cooldown: NoCooldown, + isPrivate: true, + interaction: async ({ interaction, env }) => {}, +}); diff --git a/src/bot/config/setup.ts b/src/bot/config/setup.ts index 6789860..2f8c49e 100644 --- a/src/bot/config/setup.ts +++ b/src/bot/config/setup.ts @@ -17,7 +17,11 @@ export interface CreateCommand extends Omit { export function createCommand({ body, ...base }: CreateCommand): Command { const { options, ...info } = body; - const payload: Command = { ...base, body: { ...info, type: ApplicationCommandTypes[body.type!] ?? ApplicationCommandTypes.ChatInput } }; + const payload: Command = { + ...base, + body: { ...info, type: ApplicationCommandTypes[body.type!] ?? ApplicationCommandTypes.ChatInput }, + pr: !!base.pr, + }; if (options) payload.body.options = optionsTranformer(options); return payload; } diff --git a/src/bot/index.ts b/src/bot/index.ts index 181fbce..920fdad 100644 --- a/src/bot/index.ts +++ b/src/bot/index.ts @@ -15,8 +15,8 @@ import { commands as cmds } from "./commands/index.js"; import { events } from "./events/index.js"; import { handleGatewayMessage } from "./gateway.js"; import type { ButtonResponse, Command } from "./types/index.js"; -import { connection, env, redis } from "./utils/db.js"; -import { oldSettingsMigration, oldSettingsMigrationBulk } from "./utils/settings.js"; +import { connection, redis } from "./utils/db.js"; + export const logger = createLogger({ name: "[BOT]" }); let routingKey = "gateway"; if (config.bot.dev) { @@ -51,12 +51,15 @@ bot.rest = createRestManager({ export const gatewayConfig = await bot.rest.getGatewayBot(); -const applicationCommands: CreateApplicationCommand[] = cmds.map((cmd) => cmd.body); +const privateCommands: CreateApplicationCommand[] = cmds.filter((cmd) => cmd.pr).map((cmd) => cmd.body); +const applicationCommands: CreateApplicationCommand[] = cmds.filter((cmd) => !cmd.pr).map((cmd) => cmd.body); export const commands = new Map(cmds.map((cmd) => [cmd.body.name, cmd])); export const buttons = new Map(Buttons.map((b) => [b.id, b])); await bot.rest.upsertGlobalApplicationCommands(applicationCommands).catch((err) => logger.warn(err)); +await bot.rest.upsertGuildApplicationCommands(config.bot.privateGuild, privateCommands); + logger.info(`${commands.size} commands deployed`); bot.transformers.desiredProperties.interaction.data = true; diff --git a/src/bot/types/command.ts b/src/bot/types/command.ts index ef51fb2..4da5b13 100644 --- a/src/bot/types/command.ts +++ b/src/bot/types/command.ts @@ -16,6 +16,7 @@ export interface Command { body: CreateSlashApplicationCommand; cooldown: CommandCooldown; isPrivate?: boolean; + pr?: boolean; } export interface CommandContext { diff --git a/src/bot/utils/premium.ts b/src/bot/utils/premium.ts index d76613b..894b8f2 100644 --- a/src/bot/utils/premium.ts +++ b/src/bot/utils/premium.ts @@ -24,6 +24,7 @@ const buttons: Array = [ }, ]; export const requiredPremium = { + content: "", embeds: [ { title: "This is a premium feature", @@ -69,9 +70,8 @@ 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)}`, + name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model + }\` - $${expense.used.toFixed(5)}`, value: ``, }); } @@ -79,9 +79,8 @@ 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)}`, + name: `${expense.type.slice(0, 1).toUpperCase()}${expense.type.slice(1)} - using \`${expense.data.model + }\` - $${expense.used.toFixed(5)}`, value: ``, }); } @@ -98,9 +97,8 @@ 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)} - `, }); } @@ -108,9 +106,8 @@ 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)} - `, }); } @@ -126,13 +123,11 @@ 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 📊", diff --git a/src/config.example.ts b/src/config.example.ts index 2eb0ba4..54c45ae 100644 --- a/src/config.example.ts +++ b/src/config.example.ts @@ -23,6 +23,7 @@ export default { intents: Intents.DirectMessages | Intents.GuildMessages, permissions: 0, dev: true, + privateGuild: "", status: [ { since: null,