mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
description locales
This commit is contained in:
parent
54121448ba
commit
5669b0e195
@ -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>;
|
||||
|
@ -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)) {
|
||||
|
@ -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') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user