Skip to content

Commit

Permalink
refactor: Remove withContext().
Browse files Browse the repository at this point in the history
  • Loading branch information
vxern committed Oct 18, 2024
1 parent d380d38 commit 73cb680
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
4 changes: 0 additions & 4 deletions source/library/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
62 changes: 31 additions & 31 deletions source/library/commands/handlers/information/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
16 changes: 0 additions & 16 deletions source/library/stores/localisations.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { ContextBuilder } from "logos:constants/contexts";
import {
type Locale,
type LocalisationLanguage,
getDiscordLocaleByLanguage,
getLogosLanguageByLocale,
isDiscordLanguage,
} from "logos:constants/languages/localisation";
import type { ReplyVisibility } from "logos/stores/interactions";
import type pino from "pino";

type RawLocalisationBuilder = (data?: Record<string, unknown>) => string | undefined;
Expand Down Expand Up @@ -238,20 +236,6 @@ class LocalisationStore {

return pluralised;
}

async withContext<T extends object, R>(
interaction: Logos.Interaction,
{ contexts, visibility }: { contexts: ContextBuilder<T>[]; visibility?: ReplyVisibility },
scope: (strings: T) => Promise<R>,
): Promise<R> {
const locale = visibility === "public" ? interaction.guildLocale : interaction.locale;

const strings = contexts
.map((builder) => builder({ localise: this.localise.bind(this), locale }))
.reduce<T>((combined, context) => Object.assign(combined, context), {} as T);

return scope(strings);
}
}

export { LocalisationStore };
Expand Down

0 comments on commit 73cb680

Please sign in to comment.