description locales

This commit is contained in:
MARCROCK22 2024-03-22 13:59:27 -04:00
parent 54121448ba
commit 5669b0e195
3 changed files with 36 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import type {
APIApplicationCommandBasicOption,
APIApplicationCommandOption,
APIApplicationCommandSubcommandGroupOption,
FlatObjectKeys,
LocaleString,
PermissionStrings,
} from '../../common';
@ -13,6 +14,7 @@ import type { Groups, RegisteredMiddlewares } from '../decorators';
import type { OptionResolver } from '../optionresolver';
import type { CommandContext } from './chatcontext';
import type {
DefaultLocale,
NextFunction,
OKFunction,
OnOptionsReturnObject,
@ -50,6 +52,10 @@ type Wrap<N extends ApplicationCommandOptionType> = N extends
description: string;
description_localizations?: APIApplicationCommandBasicOption['description_localizations'];
name_localizations?: APIApplicationCommandBasicOption['name_localizations'];
locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
};
export type __TypeWrapper<T extends ApplicationCommandOptionType> = Wrap<T>;

View File

@ -135,6 +135,30 @@ export class CommandHandler extends BaseHandler {
}
}
for (const options of command.options ?? []) {
if (options instanceof SubCommand || !options.locales) continue;
options.name_localizations = {};
options.description_localizations = {};
for (const locale of Object.keys(client.langs.values)) {
const locales = this.client.langs.aliases.find(x => x[0] === locale)?.[1] ?? [];
if (Object.values<string>(Locale).includes(locale)) locales.push(locale as LocaleString);
if (options.locales.name) {
for (const i of locales) {
const valueName = client.langs.getKey(locale, options.locales.name!);
if (valueName) options.name_localizations[i] = valueName;
}
}
if (options.locales.description) {
for (const i of locales) {
const valueKey = client.langs.getKey(locale, options.locales.description!);
if (valueKey) options.description_localizations[i] = valueKey;
}
}
}
}
if (command instanceof Command && command.__tGroups) {
command.groups = {};
for (const locale of Object.keys(client.langs.values)) {

View File

@ -15,8 +15,12 @@ export class LangsHandler extends BaseHandler {
getKey(lang: string, message: string) {
let value = this.values[lang as string];
for (const i of message.split('.')) {
value = value[i];
try {
for (const i of message.split('.')) {
value = value[i];
}
} catch {
return;
}
if (typeof value !== 'string') {