mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: update bot chunk 4
This commit is contained in:
1 parent
5499cb5cca
commit
98724df711
11 files changed
+122
-91
No files matched your search
@@ -26,7 +26,7 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
.setName('threshold')
|
.setName('threshold')
|
||||||
.setNameLocalizations(
|
.setNameLocalizations(
|
||||||
localizationObject(
|
localizationObject(
|
||||||
'bot.commands.inactive.options.threshold',
|
(strings) => strings.bot.commands.inactive.options.threshold.$,
|
||||||
undefined,
|
undefined,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
@@ -36,7 +36,8 @@ export const inactiveCommand = new Promise<CommandRegistry>((resolve) => {
|
|||||||
)
|
)
|
||||||
.setDescriptionLocalizations(
|
.setDescriptionLocalizations(
|
||||||
localizationObject(
|
localizationObject(
|
||||||
'bot.commands.inactive.options.threshold.description',
|
(strings) =>
|
||||||
|
strings.bot.commands.inactive.options.threshold.description,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.setMinValue(0);
|
.setMinValue(0);
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ export function translator(localeRaw: Locale) {
|
|||||||
SUPPORTED_LOCALES_DISCORD.includes(localeRaw)
|
SUPPORTED_LOCALES_DISCORD.includes(localeRaw)
|
||||||
? localeRaw
|
? localeRaw
|
||||||
: DEFAULT_LOCALE_DISCORD;
|
: DEFAULT_LOCALE_DISCORD;
|
||||||
STRINGS;
|
|
||||||
const strings = STRINGS[SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]];
|
const strings = STRINGS[SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]];
|
||||||
|
|
||||||
const unwrap = unwrapper(SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]);
|
const unwrap = unwrapper(SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]);
|
||||||
|
|
||||||
return { locale, strings, unwrap };
|
return { locale, strings, unwrap };
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import {
|
|||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
AttachmentBuilder,
|
AttachmentBuilder,
|
||||||
ButtonBuilder,
|
ButtonBuilder,
|
||||||
|
ButtonStyle,
|
||||||
CacheType,
|
CacheType,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
InteractionReplyOptions,
|
InteractionReplyOptions,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { InteractionRawReturnable, commands } from '..';
|
import { InteractionRawReturnable, commands } from '..';
|
||||||
|
import { UserError } from '../../../core/blitzkit/userError';
|
||||||
import { buttonLink } from '../../../core/discord/buttonLink';
|
import { buttonLink } from '../../../core/discord/buttonLink';
|
||||||
import { embedWarning } from '../../../core/discord/embedWarning';
|
import { embedWarning } from '../../../core/discord/embedWarning';
|
||||||
import { normalizeInteractionReturnable } from '../../../core/discord/normalizeInteractionReturnable';
|
import { normalizeInteractionReturnable } from '../../../core/discord/normalizeInteractionReturnable';
|
||||||
@@ -124,26 +126,27 @@ export async function handleChatInputCommand(
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const { t } = translator(interaction.locale);
|
const { strings } = translator(interaction.locale);
|
||||||
// const components = [
|
|
||||||
// new ActionRowBuilder<ButtonBuilder>().addComponents(
|
const components = [
|
||||||
// new ButtonBuilder()
|
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||||
// .setLabel(t`bot.common.errors.get_help`)
|
new ButtonBuilder()
|
||||||
// .setURL('https://discord.gg/nDt7AjGJQH')
|
.setLabel(strings.bot.common.errors.get_help)
|
||||||
// .setStyle(ButtonStyle.Link),
|
.setURL('https://discord.gg/nDt7AjGJQH')
|
||||||
// ),
|
.setStyle(ButtonStyle.Link),
|
||||||
// ];
|
),
|
||||||
// if (error instanceof UserError) {
|
];
|
||||||
// interaction.editReply({
|
if (error instanceof UserError) {
|
||||||
// content: error.message,
|
interaction.editReply({
|
||||||
// components,
|
content: error.message,
|
||||||
// });
|
components,
|
||||||
// } else {
|
});
|
||||||
// console.error(interaction.commandName, error);
|
} else {
|
||||||
// interaction.editReply({
|
console.error(interaction.commandName, error);
|
||||||
// content: t`bot.common.errors.uncaught_error`,
|
interaction.editReply({
|
||||||
// components,
|
content: strings.bot.common.errors.uncaught_error,
|
||||||
// });
|
components,
|
||||||
// }
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { assertSecret } from '@blitzkit/core';
|
||||||
import {
|
import {
|
||||||
AttachmentBuilder,
|
AttachmentBuilder,
|
||||||
AutocompleteInteraction,
|
AutocompleteInteraction,
|
||||||
@@ -7,11 +8,36 @@ import {
|
|||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
Interaction,
|
Interaction,
|
||||||
|
REST,
|
||||||
|
Routes,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
SlashCommandOptionsOnlyBuilder,
|
SlashCommandOptionsOnlyBuilder,
|
||||||
SlashCommandSubcommandsOnlyBuilder,
|
SlashCommandSubcommandsOnlyBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
import { aboutCommand } from '../../commands/about';
|
||||||
|
import { auctionCommand } from '../../commands/auction';
|
||||||
|
import { breakdownCommand } from '../../commands/breakdown';
|
||||||
|
import { debugCommand } from '../../commands/debug';
|
||||||
|
import { evolutionCommand } from '../../commands/evolution';
|
||||||
|
import { fullStatsCommand } from '../../commands/fullStats';
|
||||||
|
import { inactiveCommand } from '../../commands/inactive';
|
||||||
|
import { verifyCommand } from '../../commands/link';
|
||||||
|
import { ownedTanksCommand } from '../../commands/ownedTanks';
|
||||||
|
import { permissionsCommand } from '../../commands/permissions';
|
||||||
|
import { pingCommand } from '../../commands/ping';
|
||||||
|
import { playerInfoCommand } from '../../commands/playerInfo';
|
||||||
|
import { ratingCommand } from '../../commands/rating';
|
||||||
|
import { ratingLeaderboardCommand } from '../../commands/ratingLeaderboard';
|
||||||
|
import { replayCommand } from '../../commands/replay';
|
||||||
|
import { researchCommand } from '../../commands/research';
|
||||||
|
import { searchClansCommand } from '../../commands/searchClans';
|
||||||
|
import { searchPlayersCommand } from '../../commands/searchPlayers';
|
||||||
|
import { statsCommand } from '../../commands/stats';
|
||||||
|
import { todayCommand } from '../../commands/today';
|
||||||
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
|
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
|
||||||
|
import { handleAutocomplete } from './handlers/autocomplete';
|
||||||
|
import { handleButton } from './handlers/button';
|
||||||
|
import { handleChatInputCommand } from './handlers/chatInputCommand';
|
||||||
|
|
||||||
export type InteractionRawReturnable =
|
export type InteractionRawReturnable =
|
||||||
| string
|
| string
|
||||||
@@ -54,63 +80,63 @@ interface CommandRegistryExplicit extends CommandRegistryBase {
|
|||||||
export type CommandRegistry = CommandRegistryImplicit | CommandRegistryExplicit;
|
export type CommandRegistry = CommandRegistryImplicit | CommandRegistryExplicit;
|
||||||
|
|
||||||
export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
|
export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
|
||||||
// auctionCommand,
|
auctionCommand,
|
||||||
// permissionsCommand,
|
permissionsCommand,
|
||||||
// debugCommand,
|
debugCommand,
|
||||||
// aboutCommand,
|
aboutCommand,
|
||||||
// inactiveCommand,
|
inactiveCommand,
|
||||||
// ownedTanksCommand,
|
ownedTanksCommand,
|
||||||
// playerInfoCommand,
|
playerInfoCommand,
|
||||||
// searchClansCommand,
|
searchClansCommand,
|
||||||
// searchPlayersCommand,
|
searchPlayersCommand,
|
||||||
// fullStatsCommand,
|
fullStatsCommand,
|
||||||
// breakdownCommand,
|
breakdownCommand,
|
||||||
// verifyCommand,
|
verifyCommand,
|
||||||
// pingCommand,
|
pingCommand,
|
||||||
// evolutionCommand,
|
evolutionCommand,
|
||||||
// statsCommand,
|
statsCommand,
|
||||||
// ratingLeaderboardCommand,
|
ratingLeaderboardCommand,
|
||||||
// todayCommand,
|
todayCommand,
|
||||||
// researchCommand,
|
researchCommand,
|
||||||
// ratingCommand,
|
ratingCommand,
|
||||||
// replayCommand,
|
replayCommand,
|
||||||
];
|
];
|
||||||
|
|
||||||
export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
|
export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
|
||||||
// return rawCommands.reduce<Record<string, CommandRegistry>>(
|
return rawCommands.reduce<Record<string, CommandRegistry>>(
|
||||||
// (commands, registry, index) => {
|
(commands, registry, index) => {
|
||||||
// if (registry.status === 'rejected') {
|
if (registry.status === 'rejected') {
|
||||||
// console.warn(
|
console.warn(
|
||||||
// `Command ${index} failed to load; skipping...`,
|
`Command ${index} failed to load; skipping...`,
|
||||||
// registry.reason,
|
registry.reason,
|
||||||
// );
|
);
|
||||||
// return commands;
|
return commands;
|
||||||
// }
|
}
|
||||||
// return { ...commands, [registry.value.command.name]: registry.value };
|
return { ...commands, [registry.value.command.name]: registry.value };
|
||||||
// },
|
},
|
||||||
// {},
|
{},
|
||||||
// );
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
|
const rest = new REST().setToken(assertSecret(import.meta.env.DISCORD_TOKEN));
|
||||||
|
|
||||||
// commands.then((awaitedCommands) => {
|
commands.then((awaitedCommands) => {
|
||||||
// const body = Object.values(awaitedCommands).map((registry) =>
|
const body = Object.values(awaitedCommands).map((registry) =>
|
||||||
// registry.command.toJSON(),
|
registry.command.toJSON(),
|
||||||
// );
|
);
|
||||||
|
|
||||||
// rest.put(
|
rest.put(
|
||||||
// Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
|
Routes.applicationCommands(assertSecret(import.meta.env.DISCORD_CLIENT_ID)),
|
||||||
// { body },
|
{ body },
|
||||||
// );
|
);
|
||||||
// });
|
});
|
||||||
|
|
||||||
export async function interactionCreate(interaction: Interaction<CacheType>) {
|
export async function interactionCreate(interaction: Interaction<CacheType>) {
|
||||||
if (interaction.isAutocomplete()) {
|
if (interaction.isAutocomplete()) {
|
||||||
// handleAutocomplete(interaction);
|
handleAutocomplete(interaction);
|
||||||
} else if (interaction.isChatInputCommand()) {
|
} else if (interaction.isChatInputCommand()) {
|
||||||
// handleChatInputCommand(interaction);
|
handleChatInputCommand(interaction);
|
||||||
} else if (interaction.isButton()) {
|
} else if (interaction.isButton()) {
|
||||||
// handleButton(interaction);
|
handleButton(interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"dependencies": {},
|
"dependencies": {
|
||||||
|
"ts-deepmerge": "^7.0.2"
|
||||||
|
},
|
||||||
"devDependencies": {}
|
"devDependencies": {}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { merge } from 'lodash-es';
|
import { writeFile } from 'fs/promises';
|
||||||
|
import { merge } from 'ts-deepmerge';
|
||||||
import en from '../strings/en.json';
|
import en from '../strings/en.json';
|
||||||
import es from '../strings/es.json';
|
import es from '../strings/es.json';
|
||||||
import fr from '../strings/fr.json';
|
import fr from '../strings/fr.json';
|
||||||
@@ -54,9 +55,7 @@ for (const locale in stringsRaw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const localeStrings = stringsRaw[locale as SupportedLocale];
|
const localeStrings = stringsRaw[locale as SupportedLocale];
|
||||||
|
|
||||||
stringsPartial[locale as SupportedLocale] = merge(
|
stringsPartial[locale as SupportedLocale] = merge(
|
||||||
{},
|
|
||||||
stringsRaw[DEFAULT_LOCALE],
|
stringsRaw[DEFAULT_LOCALE],
|
||||||
localeStrings,
|
localeStrings,
|
||||||
);
|
);
|
||||||
@@ -71,6 +70,8 @@ export const STRINGS = stringsPartial as Record<
|
|||||||
BlitzKitStrings
|
BlitzKitStrings
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
writeFile('test.json', JSON.stringify(STRINGS, null, 2));
|
||||||
|
|
||||||
export type SupportedLocale = keyof typeof stringsRaw;
|
export type SupportedLocale = keyof typeof stringsRaw;
|
||||||
|
|
||||||
export const SUPPORTED_LOCALE_BLITZ_MAP: Record<SupportedLocale, string> = {
|
export const SUPPORTED_LOCALE_BLITZ_MAP: Record<SupportedLocale, string> = {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
sumCompositeStats,
|
sumCompositeStats,
|
||||||
type IndividualTankStats,
|
type IndividualTankStats,
|
||||||
} from '@blitzkit/core';
|
} from '@blitzkit/core';
|
||||||
import { localizedStrings } from '@blitzkit/i18n';
|
import { STRINGS } from '@blitzkit/i18n';
|
||||||
import { ReloadIcon } from '@radix-ui/react-icons';
|
import { ReloadIcon } from '@radix-ui/react-icons';
|
||||||
import { ContextMenu } from '@radix-ui/themes';
|
import { ContextMenu } from '@radix-ui/themes';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
@@ -21,15 +21,12 @@ import { BreakdownEmbedCard, BreakdownEmbedWrapper } from '../TanksEmbed';
|
|||||||
|
|
||||||
export const compositeStatsKeysOptions = compositeStatsKeys.map((value) => ({
|
export const compositeStatsKeysOptions = compositeStatsKeys.map((value) => ({
|
||||||
value,
|
value,
|
||||||
locales: Object.entries(localizedStrings).reduce(
|
locales: Object.entries(STRINGS).reduce((accumulator, [locale, strings]) => {
|
||||||
(accumulator, [locale, strings]) => {
|
return {
|
||||||
return {
|
...accumulator,
|
||||||
...accumulator,
|
[locale]: strings.common.composite_stats[value],
|
||||||
[locale]: strings.common.composite_stats[value],
|
};
|
||||||
};
|
}, {}),
|
||||||
},
|
|
||||||
{},
|
|
||||||
),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const [tankDefinitions, averageDefinitions] = await Promise.all([
|
const [tankDefinitions, averageDefinitions] = await Promise.all([
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {} from '@blitzkit/core';
|
import {} from '@blitzkit/core';
|
||||||
import {
|
import {
|
||||||
DEFAULT_LOCALE,
|
DEFAULT_LOCALE,
|
||||||
|
STRINGS,
|
||||||
SUPPORTED_LOCALES,
|
SUPPORTED_LOCALES,
|
||||||
SUPPORTED_LOCALE_FLAGS,
|
SUPPORTED_LOCALE_FLAGS,
|
||||||
localizedStrings,
|
|
||||||
} from '@blitzkit/i18n';
|
} from '@blitzkit/i18n';
|
||||||
import { Select } from '@radix-ui/themes';
|
import { Select } from '@radix-ui/themes';
|
||||||
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
import type { LocaleAcceptorProps } from '../hooks/useLocale';
|
||||||
@@ -44,7 +44,7 @@ export function LocaleSwitcher({ locale }: LocaleAcceptorProps) {
|
|||||||
{SUPPORTED_LOCALES.map((locale) => (
|
{SUPPORTED_LOCALES.map((locale) => (
|
||||||
<Select.Item key={locale} value={locale}>
|
<Select.Item key={locale} value={locale}>
|
||||||
{SUPPORTED_LOCALE_FLAGS[locale]}{' '}
|
{SUPPORTED_LOCALE_FLAGS[locale]}{' '}
|
||||||
{localizedStrings[locale].common.locales[locale]}
|
{STRINGS[locale].common.locales[locale]}
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
))}
|
))}
|
||||||
</Select.Content>
|
</Select.Content>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { assertSecret } from '@blitzkit/core';
|
import { assertSecret } from '@blitzkit/core';
|
||||||
import { DEFAULT_LOCALE, localizedStrings } from '@blitzkit/i18n';
|
import { DEFAULT_LOCALE, STRINGS, type SupportedLocale } from '@blitzkit/i18n';
|
||||||
|
|
||||||
export function resolveBranchName(locale: string = DEFAULT_LOCALE) {
|
export function resolveBranchName(locale: string = DEFAULT_LOCALE) {
|
||||||
const strings = localizedStrings[locale];
|
if (!(locale in STRINGS)) throw new Error(`Unsupported locale: ${locale}`);
|
||||||
|
|
||||||
|
const strings = STRINGS[locale as SupportedLocale];
|
||||||
const secret = assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH);
|
const secret = assertSecret(import.meta.env.PUBLIC_ASSET_BRANCH);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { DEFAULT_LOCALE, localizedStrings } from '@blitzkit/i18n';
|
import { DEFAULT_LOCALE, STRINGS, type SupportedLocale } from '@blitzkit/i18n';
|
||||||
|
|
||||||
export function getStrings(locale: string = DEFAULT_LOCALE) {
|
export function getStrings(locale: string = DEFAULT_LOCALE) {
|
||||||
return localizedStrings[locale];
|
if (locale in STRINGS) return STRINGS[locale as SupportedLocale];
|
||||||
|
throw new Error(`Unsupported locale: ${locale}`);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user