From 73cb68073f6a639c5cdcb7a4f42089ca22d29e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Oszcz=C4=99da?= Date: Sat, 19 Oct 2024 00:10:34 +0100 Subject: [PATCH] refactor: Remove `withContext()`. --- source/library/client.ts | 4 -- .../commands/handlers/information/bot.ts | 62 +++++++++---------- source/library/stores/localisations.ts | 16 ----- 3 files changed, 31 insertions(+), 51 deletions(-) diff --git a/source/library/client.ts b/source/library/client.ts index 2ad8ae174..ef3d131ca 100644 --- a/source/library/client.ts +++ b/source/library/client.ts @@ -51,10 +51,6 @@ class Client { return this.#localisations.pluralise.bind(this.#localisations); } - get withContext(): LocalisationStore["withContext"] { - return this.#localisations.withContext.bind(this.#localisations); - } - get commands(): CommandStore["commands"] { return this.#commands.commands; } diff --git a/source/library/commands/handlers/information/bot.ts b/source/library/commands/handlers/information/bot.ts index f1864835f..cb95f7254 100644 --- a/source/library/commands/handlers/information/bot.ts +++ b/source/library/commands/handlers/information/bot.ts @@ -7,39 +7,39 @@ async function handleDisplayBotInformation(client: Client, interaction: Logos.In return; } - client - .withContext(interaction, { contexts: [constants.contexts.botInformation] }, async (context) => { - const featuresFormatted = list([ - `${constants.emojis.bot.features.definitions} ${context.function.features.definitions}`, - `${constants.emojis.bot.features.translations} ${context.function.features.translations}`, - `${constants.emojis.bot.features.games} ${context.function.features.games}`, - `${constants.emojis.bot.features.messages} ${context.function.features.messages}`, - `${constants.emojis.bot.features.guides} ${context.function.features.guides}`, - ]); + const strings = constants.contexts.botInformation({ localise: client.localise, locale: interaction.displayLocale }); + + const featuresFormatted = list([ + `${constants.emojis.bot.features.definitions} ${strings.function.features.definitions}`, + `${constants.emojis.bot.features.translations} ${strings.function.features.translations}`, + `${constants.emojis.bot.features.games} ${strings.function.features.games}`, + `${constants.emojis.bot.features.messages} ${strings.function.features.messages}`, + `${constants.emojis.bot.features.guides} ${strings.function.features.guides}`, + ]); - await client.notice(interaction, { - author: { - iconUrl: Discord.avatarUrl(client.bot.id, botUser.discriminator, { - avatar: botUser.avatar ?? undefined, - format: "png", - }), - name: botUser.username, + client + .notice(interaction, { + author: { + iconUrl: Discord.avatarUrl(client.bot.id, botUser.discriminator, { + avatar: botUser.avatar ?? undefined, + format: "png", + }), + name: botUser.username, + }, + fields: [ + { + name: `${constants.emojis.information.bot} ${strings.concept.title}`, + value: strings.concept.description, + }, + { + name: `${constants.emojis.information.function} ${strings.function.title}`, + value: `${strings.function.description}\n${featuresFormatted}`, + }, + { + name: `${constants.emojis.information.languages} ${strings.languages.title}`, + value: strings.languages.description, }, - fields: [ - { - name: `${constants.emojis.information.bot} ${context.concept.title}`, - value: context.concept.description, - }, - { - name: `${constants.emojis.information.function} ${context.function.title}`, - value: `${context.function.description}\n${featuresFormatted}`, - }, - { - name: `${constants.emojis.information.languages} ${context.languages.title}`, - value: context.languages.description, - }, - ], - }); + ], }) .ignore(); } diff --git a/source/library/stores/localisations.ts b/source/library/stores/localisations.ts index f4eec4c91..8c3df32a2 100644 --- a/source/library/stores/localisations.ts +++ b/source/library/stores/localisations.ts @@ -1,4 +1,3 @@ -import type { ContextBuilder } from "logos:constants/contexts"; import { type Locale, type LocalisationLanguage, @@ -6,7 +5,6 @@ import { getLogosLanguageByLocale, isDiscordLanguage, } from "logos:constants/languages/localisation"; -import type { ReplyVisibility } from "logos/stores/interactions"; import type pino from "pino"; type RawLocalisationBuilder = (data?: Record) => string | undefined; @@ -238,20 +236,6 @@ class LocalisationStore { return pluralised; } - - async withContext( - interaction: Logos.Interaction, - { contexts, visibility }: { contexts: ContextBuilder[]; visibility?: ReplyVisibility }, - scope: (strings: T) => Promise, - ): Promise { - const locale = visibility === "public" ? interaction.guildLocale : interaction.locale; - - const strings = contexts - .map((builder) => builder({ localise: this.localise.bind(this), locale })) - .reduce((combined, context) => Object.assign(combined, context), {} as T); - - return scope(strings); - } } export { LocalisationStore };