mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
feat: ajouter la résolution de la langue pour les commandes de préfixe
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import type { Message } from "discord.js";
|
import type { Message } from "discord.js";
|
||||||
|
import type { BotCommand, SupportedLang } from "../types/command.js";
|
||||||
|
|
||||||
import { parsePrefixArgs } from "../commands/argParser.js";
|
import { parsePrefixArgs } from "../commands/argParser.js";
|
||||||
import { buildPrefixUsage } from "../commands/usage.js";
|
import { buildPrefixUsage } from "../commands/usage.js";
|
||||||
@@ -14,6 +15,24 @@ interface PrefixHandlerDeps extends HandlerExecutionDeps {
|
|||||||
executor: CommandExecutor;
|
executor: CommandExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolvePrefixLang = (
|
||||||
|
deps: PrefixHandlerDeps,
|
||||||
|
command: BotCommand,
|
||||||
|
trigger: string,
|
||||||
|
fallbackLang: SupportedLang,
|
||||||
|
guildPreferredLocale?: string | null,
|
||||||
|
): SupportedLang => {
|
||||||
|
|
||||||
|
const contextualLang = deps.i18n.resolveLang(guildPreferredLocale);
|
||||||
|
const contextualTrigger = deps.i18n.commandTrigger(contextualLang, command.meta.name);
|
||||||
|
|
||||||
|
if (contextualTrigger === trigger) {
|
||||||
|
return contextualLang;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackLang;
|
||||||
|
};
|
||||||
|
|
||||||
export const createPrefixHandler = (deps: PrefixHandlerDeps) => {
|
export const createPrefixHandler = (deps: PrefixHandlerDeps) => {
|
||||||
return async (message: Message): Promise<void> => {
|
return async (message: Message): Promise<void> => {
|
||||||
if (message.author.bot || !message.content.startsWith(deps.prefix)) {
|
if (message.author.bot || !message.content.startsWith(deps.prefix)) {
|
||||||
@@ -37,7 +56,7 @@ export const createPrefixHandler = (deps: PrefixHandlerDeps) => {
|
|||||||
const reply = createPrefixReply(message);
|
const reply = createPrefixReply(message);
|
||||||
|
|
||||||
const command = match.command;
|
const command = match.command;
|
||||||
const lang = match.lang;
|
const lang = resolvePrefixLang(deps, command, trigger, match.lang, message.guild?.preferredLocale ?? null);
|
||||||
const t = createTranslator(deps.i18n, lang);
|
const t = createTranslator(deps.i18n, lang);
|
||||||
|
|
||||||
const parsed = await parsePrefixArgs(message, command.args, rawArgs);
|
const parsed = await parsePrefixArgs(message, command.args, rawArgs);
|
||||||
|
|||||||
Reference in New Issue
Block a user