mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
fix: use stricter localizaiton
This commit is contained in:
1 parent
768c420ae4
commit
f396d6c4a1
16 files changed
+101
-36
No files matched your search
@@ -24,7 +24,11 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
return option
|
||||
.setName('threshold')
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.commands.inactive.options.threshold'),
|
||||
localizationObject(
|
||||
'bot.commands.inactive.options.threshold',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.commands.inactive.options.threshold.description'),
|
||||
|
||||
@@ -63,6 +63,8 @@ export const ratingLeaderboardCommand = new Promise<CommandRegistry>(
|
||||
.setNameLocalizations(
|
||||
localizationObject(
|
||||
'bot.commands.rating_leaderboard.options.limit',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
@@ -87,6 +89,8 @@ export const ratingLeaderboardCommand = new Promise<CommandRegistry>(
|
||||
.setNameLocalizations(
|
||||
localizationObject(
|
||||
'bot.commands.rating_leaderboard.options.season',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
@@ -148,6 +152,8 @@ export const ratingLeaderboardCommand = new Promise<CommandRegistry>(
|
||||
.setNameLocalizations(
|
||||
localizationObject(
|
||||
'bot.commands.rating_leaderboard.options.league',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
|
||||
@@ -36,7 +36,11 @@ export const researchCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
option
|
||||
.setName(t`bot.commands.research.options.target_tank`)
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.commands.research.options.target_tank'),
|
||||
localizationObject(
|
||||
'bot.commands.research.options.target_tank',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
t`bot.commands.research.options.target_tank.description`,
|
||||
@@ -53,7 +57,11 @@ export const researchCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
option
|
||||
.setName(t`bot.commands.research.options.starting_tank`)
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.commands.research.options.starting_tank'),
|
||||
localizationObject(
|
||||
'bot.commands.research.options.starting_tank',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
t`bot.commands.research.options.starting_tank.description`,
|
||||
|
||||
@@ -24,7 +24,11 @@ export const searchClansCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
return option
|
||||
.setName(t`bot.commands.search_clans.options.limit`)
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.commands.search_clans.options.limit'),
|
||||
localizationObject(
|
||||
'bot.commands.search_clans.options.limit',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.commands.search_clans.options.limit.description', [
|
||||
|
||||
@@ -29,7 +29,11 @@ export const searchPlayersCommand = new Promise<CommandRegistry>((resolve) => {
|
||||
option
|
||||
.setName(t`bot.commands.search_players.options.limit`)
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.commands.search_players.options.limit'),
|
||||
localizationObject(
|
||||
'bot.commands.search_players.options.limit',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.commands.search_players.options.limit.description', [
|
||||
|
||||
@@ -7,7 +7,9 @@ export function addClanChoices(option: SlashCommandStringOption) {
|
||||
|
||||
return option
|
||||
.setName('clan')
|
||||
.setNameLocalizations(localizationObject('bot.common.options.clan'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.clan', undefined, true),
|
||||
)
|
||||
.setDescription(translate('bot.common.options.clan.description'))
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.clan.description'),
|
||||
|
||||
@@ -25,7 +25,11 @@ export function addFilterOptions<
|
||||
option
|
||||
.setName(translate('bot.common.options.filters.nation'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.filters.nation'),
|
||||
localizationObject(
|
||||
'bot.common.options.filters.nation',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.common.options.filters.nation.description'),
|
||||
@@ -52,7 +56,11 @@ export function addFilterOptions<
|
||||
option
|
||||
.setName(translate('bot.common.options.filters.class'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.filters.class'),
|
||||
localizationObject(
|
||||
'bot.common.options.filters.class',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.common.options.filters.class.description'),
|
||||
@@ -78,7 +86,11 @@ export function addFilterOptions<
|
||||
option
|
||||
.setName(translate('bot.common.options.filters.type'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.filters.type'),
|
||||
localizationObject(
|
||||
'bot.common.options.filters.type',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
)
|
||||
.setDescription(
|
||||
translate('bot.common.options.filters.type.description'),
|
||||
|
||||
@@ -18,12 +18,20 @@ export function addPeriodSubCommands(
|
||||
) {
|
||||
const { translate } = translator(Locale.EnglishUS);
|
||||
const subcommandNameLocalizations = {
|
||||
today: localizationObject('bot.common.subcommands.today'),
|
||||
30: localizationObject('bot.common.subcommands.30'),
|
||||
60: localizationObject('bot.common.subcommands.60'),
|
||||
90: localizationObject('bot.common.subcommands.90'),
|
||||
career: localizationObject('bot.common.subcommands.career'),
|
||||
custom: localizationObject('bot.common.subcommands.custom'),
|
||||
today: localizationObject('bot.common.subcommands.today', undefined, true),
|
||||
30: localizationObject('bot.common.subcommands.30', undefined, true),
|
||||
60: localizationObject('bot.common.subcommands.60', undefined, true),
|
||||
90: localizationObject('bot.common.subcommands.90', undefined, true),
|
||||
career: localizationObject(
|
||||
'bot.common.subcommands.career',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
custom: localizationObject(
|
||||
'bot.common.subcommands.custom',
|
||||
undefined,
|
||||
true,
|
||||
),
|
||||
};
|
||||
const subcommandDescriptionLocalizations = {
|
||||
today: localizationObject('bot.common.subcommands.today.description'),
|
||||
|
||||
@@ -12,7 +12,9 @@ export function addRegionChoices(option: SlashCommandStringOption) {
|
||||
|
||||
return option
|
||||
.setName(t`bot.common.options.region`)
|
||||
.setNameLocalizations(localizationObject('bot.common.options.region'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.region', undefined, true),
|
||||
)
|
||||
.setDescription(t`bot.common.options.region.description`)
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.region.description'),
|
||||
|
||||
@@ -7,7 +7,9 @@ export function addTankChoices(option: SlashCommandStringOption) {
|
||||
|
||||
return option
|
||||
.setName(translate('bot.common.options.tank'))
|
||||
.setNameLocalizations(localizationObject('bot.common.options.tank'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.tank', undefined, true),
|
||||
)
|
||||
.setDescription(translate('bot.common.options.tank.description'))
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.tank.description'),
|
||||
|
||||
@@ -13,7 +13,9 @@ export function addTierChoices(option: SlashCommandStringOption) {
|
||||
|
||||
return option
|
||||
.setName(t`bot.common.options.tier`)
|
||||
.setNameLocalizations(localizationObject('bot.common.options.tier'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.tier', undefined, true),
|
||||
)
|
||||
.setDescription(t`bot.common.options.tier.description`)
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.tier.description'),
|
||||
|
||||
@@ -7,7 +7,9 @@ export function addUsernameChoices(option: SlashCommandStringOption) {
|
||||
|
||||
return option
|
||||
.setName(t`bot.common.options.username`)
|
||||
.setNameLocalizations(localizationObject('bot.common.options.username'))
|
||||
.setNameLocalizations(
|
||||
localizationObject('bot.common.options.username', undefined, true),
|
||||
)
|
||||
.setDescription(t`bot.common.options.username.description`)
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject('bot.common.options.username.description'),
|
||||
|
||||
@@ -27,7 +27,9 @@ export function createLocalizedCommand(
|
||||
const { translate } = translator(Locale.EnglishUS);
|
||||
const slashCommand = new SlashCommandBuilder()
|
||||
.setName(command)
|
||||
.setNameLocalizations(localizationObject(`bot.commands.${commandPathItem}`))
|
||||
.setNameLocalizations(
|
||||
localizationObject(`bot.commands.${commandPathItem}`, undefined, true),
|
||||
)
|
||||
.setDescription(translate(`bot.commands.${commandPathItem}.description`))
|
||||
.setDescriptionLocalizations(
|
||||
localizationObject(`bot.commands.${commandPathItem}.description`),
|
||||
@@ -38,6 +40,8 @@ export function createLocalizedCommand(
|
||||
if ('subcommand' in subItem) {
|
||||
const subcommandNameLocalizations = localizationObject(
|
||||
`bot.commands.${commandPathItem}.subcommands.${subItem.subcommand}`,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
const subcommandDescriptionLocalizations = localizationObject(
|
||||
`bot.commands.${commandPathItem}.subcommands.${subItem.subcommand}.description`,
|
||||
@@ -59,6 +63,8 @@ export function createLocalizedCommand(
|
||||
} else {
|
||||
const subcommandNameLocalizations = localizationObject(
|
||||
`bot.commands.${commandPathItem}.groups.${subItem.group}`,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
const subcommandDescriptionLocalizations = localizationObject(
|
||||
`bot.commands.${commandPathItem}.groups.${subItem.group}.description`,
|
||||
|
||||
@@ -2,13 +2,29 @@ import { Locale } from 'discord.js';
|
||||
import { SUPPORTED_LOCALES } from '../localization/strings/constants';
|
||||
import { translator } from '../localization/translator';
|
||||
|
||||
export function localizationObject(path: string, literals?: string[]) {
|
||||
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
|
||||
|
||||
export function localizationObject(
|
||||
path: string,
|
||||
literals?: string[],
|
||||
strict = false,
|
||||
) {
|
||||
return SUPPORTED_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||
(localizations, locale) => {
|
||||
const { translate } = translator(locale);
|
||||
const translation = translate(path, literals);
|
||||
const isValid = !strict || validNameRegex.test(translation);
|
||||
|
||||
if (!isValid) {
|
||||
console.warn(
|
||||
`Invalid localization for ${locale} (${path}): ${translation}; skipping...`,
|
||||
);
|
||||
return localizations;
|
||||
}
|
||||
|
||||
return {
|
||||
...localizations,
|
||||
[locale]: translate(path, literals),
|
||||
[locale]: translation,
|
||||
};
|
||||
},
|
||||
{},
|
||||
|
||||
@@ -126,9 +126,7 @@ commands.then((awaitedCommands) => {
|
||||
|
||||
rest.put(
|
||||
Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
|
||||
{
|
||||
body,
|
||||
},
|
||||
{ body },
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -7,19 +7,8 @@ import { manager } from './core/discord/manager';
|
||||
|
||||
console.log('pre manager event listeners and spawn');
|
||||
|
||||
let isFirst = true;
|
||||
const interval = setInterval(() => {
|
||||
if (!isFirst) {
|
||||
console.warn('respawning all shards because manager died');
|
||||
manager.respawnAll();
|
||||
}
|
||||
|
||||
isFirst = false;
|
||||
}, 5000);
|
||||
|
||||
const shards = await manager
|
||||
.on('shardCreate', (shard) => {
|
||||
clearInterval(interval);
|
||||
console.log(`🟡 Launching shard ${shard.id}`);
|
||||
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user