mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
description locales
This commit is contained in:
parent
54121448ba
commit
5669b0e195
@ -4,6 +4,7 @@ import type {
|
|||||||
APIApplicationCommandBasicOption,
|
APIApplicationCommandBasicOption,
|
||||||
APIApplicationCommandOption,
|
APIApplicationCommandOption,
|
||||||
APIApplicationCommandSubcommandGroupOption,
|
APIApplicationCommandSubcommandGroupOption,
|
||||||
|
FlatObjectKeys,
|
||||||
LocaleString,
|
LocaleString,
|
||||||
PermissionStrings,
|
PermissionStrings,
|
||||||
} from '../../common';
|
} from '../../common';
|
||||||
@ -13,6 +14,7 @@ import type { Groups, RegisteredMiddlewares } from '../decorators';
|
|||||||
import type { OptionResolver } from '../optionresolver';
|
import type { OptionResolver } from '../optionresolver';
|
||||||
import type { CommandContext } from './chatcontext';
|
import type { CommandContext } from './chatcontext';
|
||||||
import type {
|
import type {
|
||||||
|
DefaultLocale,
|
||||||
NextFunction,
|
NextFunction,
|
||||||
OKFunction,
|
OKFunction,
|
||||||
OnOptionsReturnObject,
|
OnOptionsReturnObject,
|
||||||
@ -50,6 +52,10 @@ type Wrap<N extends ApplicationCommandOptionType> = N extends
|
|||||||
description: string;
|
description: string;
|
||||||
description_localizations?: APIApplicationCommandBasicOption['description_localizations'];
|
description_localizations?: APIApplicationCommandBasicOption['description_localizations'];
|
||||||
name_localizations?: APIApplicationCommandBasicOption['name_localizations'];
|
name_localizations?: APIApplicationCommandBasicOption['name_localizations'];
|
||||||
|
locales?: {
|
||||||
|
name?: FlatObjectKeys<DefaultLocale>;
|
||||||
|
description?: FlatObjectKeys<DefaultLocale>;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type __TypeWrapper<T extends ApplicationCommandOptionType> = Wrap<T>;
|
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) {
|
if (command instanceof Command && command.__tGroups) {
|
||||||
command.groups = {};
|
command.groups = {};
|
||||||
for (const locale of Object.keys(client.langs.values)) {
|
for (const locale of Object.keys(client.langs.values)) {
|
||||||
|
@ -15,9 +15,13 @@ export class LangsHandler extends BaseHandler {
|
|||||||
getKey(lang: string, message: string) {
|
getKey(lang: string, message: string) {
|
||||||
let value = this.values[lang as string];
|
let value = this.values[lang as string];
|
||||||
|
|
||||||
|
try {
|
||||||
for (const i of message.split('.')) {
|
for (const i of message.split('.')) {
|
||||||
value = value[i];
|
value = value[i];
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user