Merge branch 'main' into dev

This commit is contained in:
tresabhi committed 2025-01-03 12:36:02 -06:00
commit 1d44ecab18
8 files changed
+49 -30

No files matched your search

+3
View File
@@ -113,6 +113,9 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: bun install run: bun install
- name: Lint
run: bun run lint:website
- name: Download depots - name: Download depots
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
BIN
View File
Binary file not shown.
@@ -1,5 +1,5 @@
import { Locale } from 'discord.js'; import { Locale } from 'discord.js';
import { SUPPORTED_DISCORD_LOCALES } from '../localization/strings/constants'; import { SUPPORTED_LOCALES_DISCORD } from '../localization/strings/constants';
import { translator } from '../localization/translator'; import { translator } from '../localization/translator';
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u; const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
@@ -9,7 +9,7 @@ export function localizationObject(
literals?: string[], literals?: string[],
strict = false, strict = false,
) { ) {
return SUPPORTED_DISCORD_LOCALES.reduce<Partial<Record<Locale, string>>>( return SUPPORTED_LOCALES_DISCORD.reduce<Partial<Record<Locale, string>>>(
(localizations, locale) => { (localizations, locale) => {
const { translate } = translator(locale); const { translate } = translator(locale);
const translation = translate(path, literals); const translation = translate(path, literals);
@@ -1,7 +1,7 @@
import { SupportedLocale } from '@blitzkit/core'; import { DEFAULT_LOCALE, SupportedLocale } from '@blitzkit/core';
import { Locale } from 'discord.js'; import { Locale } from 'discord.js';
const DISCORD_SUPPORTED_LOCALES: Record<SupportedLocale, Locale> = { const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
en: Locale.EnglishUS, en: Locale.EnglishUS,
es: Locale.SpanishES, es: Locale.SpanishES,
hr: Locale.Croatian, hr: Locale.Croatian,
@@ -11,6 +11,13 @@ const DISCORD_SUPPORTED_LOCALES: Record<SupportedLocale, Locale> = {
zh: Locale.ChineseCN, zh: Locale.ChineseCN,
}; };
export const SUPPORTED_DISCORD_LOCALES = Object.values( export const SUPPORTED_LOCALES_DISCORD_MAP_INVERSE = Object.fromEntries(
DISCORD_SUPPORTED_LOCALES, Object.entries(SUPPORTED_LOCALES_DISCORD_MAP).map(([k, v]) => [v, k]),
) as Record<Locale, SupportedLocale>;
export const SUPPORTED_LOCALES_DISCORD = Object.values(
SUPPORTED_LOCALES_DISCORD_MAP,
); );
export const DEFAULT_LOCALE_DISCORD =
SUPPORTED_LOCALES_DISCORD_MAP[DEFAULT_LOCALE];
@@ -1,5 +1,8 @@
import { Locale } from 'discord.js'; import { Locale } from 'discord.js';
import { SUPPORTED_DISCORD_LOCALES } from './constants'; import {
SUPPORTED_LOCALES_DISCORD,
SUPPORTED_LOCALES_DISCORD_MAP_INVERSE,
} from './constants';
export type TranslationFragmentTree = { export type TranslationFragmentTree = {
[key: string]: TranslationFragment; [key: string]: TranslationFragment;
@@ -8,12 +11,14 @@ export type TranslationFragmentTree = {
}; };
export type TranslationFragment = string | TranslationFragmentTree; export type TranslationFragment = string | TranslationFragmentTree;
export const translations = SUPPORTED_DISCORD_LOCALES.reduce< export const translations = SUPPORTED_LOCALES_DISCORD.reduce<
Partial<Record<Locale, TranslationFragment>> Partial<Record<Locale, TranslationFragment>>
>( >(
(table, locale) => ({ (table, locale) => ({
...table, ...table,
[locale]: require(`../../../../../core/lang/${locale}.json`), [locale]: require(
`../../../../../core/lang/${SUPPORTED_LOCALES_DISCORD_MAP_INVERSE[locale]}.json`,
),
}), }),
{}, {},
); );
@@ -1,13 +1,16 @@
import { Locale } from 'discord.js'; import { Locale } from 'discord.js';
import { translations } from './strings'; import { translations } from './strings';
import { SUPPORTED_DISCORD_LOCALES } from './strings/constants'; import {
DEFAULT_LOCALE_DISCORD,
SUPPORTED_LOCALES_DISCORD,
} from './strings/constants';
export function translator(localeRaw: Locale) { export function translator(localeRaw: Locale) {
const locale = const locale =
localeRaw !== Locale.EnglishUS && localeRaw !== DEFAULT_LOCALE_DISCORD &&
SUPPORTED_DISCORD_LOCALES.includes(localeRaw) SUPPORTED_LOCALES_DISCORD.includes(localeRaw)
? localeRaw ? localeRaw
: Locale.EnglishUS; : DEFAULT_LOCALE_DISCORD;
const strings = translations[locale]!; const strings = translations[locale]!;
function translate(path: string, literals?: string[]): string { function translate(path: string, literals?: string[]): string {
@@ -26,11 +29,11 @@ export function translator(localeRaw: Locale) {
if (typeof fragment === 'undefined') { if (typeof fragment === 'undefined') {
const message = `Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"`; const message = `Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"`;
if (locale === Locale.EnglishUS) { if (locale === DEFAULT_LOCALE_DISCORD) {
throw new Error(message); throw new Error(message);
} else { } else {
console.warn(`${message} falling back to en-US`); console.warn(`${message} falling back to en-US`);
return translator(Locale.EnglishUS).translate(path, literals); return translator(DEFAULT_LOCALE_DISCORD).translate(path, literals);
} }
} }
} }
+15 -14
View File
@@ -1,27 +1,30 @@
import { assertSecret, EventManager } from '@blitzkit/core'; // import { assertSecret, EventManager } from '@blitzkit/core';
// import { ActivityType, ShardingManager } from 'discord.js';
// import {
// discoveredIdsDefinitions,
// tankDefinitions,
// } from './core/blitzkit/nonBlockingPromises';
import { assertSecret } from '@blitzkit/core';
import { ActivityType, ShardingManager } from 'discord.js'; import { ActivityType, ShardingManager } from 'discord.js';
import { import {
discoveredIdsDefinitions, discoveredIdsDefinitions,
tankDefinitions, tankDefinitions,
} from './core/blitzkit/nonBlockingPromises'; } from './core/blitzkit/nonBlockingPromises';
const somethingEvent = new EventManager(); let iteration = 0;
const interval = setInterval(async () => {
iteration++;
console.log(`Attempting launch on iteration ${iteration}`);
somethingEvent.on(async () => {
const manager = new ShardingManager('dist/bot/workers/bot.js', { const manager = new ShardingManager('dist/bot/workers/bot.js', {
token: assertSecret(import.meta.env.DISCORD_TOKEN), token: assertSecret(import.meta.env.DISCORD_TOKEN),
}); });
const timeout = setTimeout(() => {
console.warn(`Shards didn't launch in 5 seconds; trying again...`);
somethingEvent.emit(undefined);
shards.forEach((shard) => shard.kill());
}, 5000);
const shards = await manager const shards = await manager
.on('shardCreate', (shard) => { .on('shardCreate', (shard) => {
clearTimeout(timeout); clearInterval(interval);
console.log(`🟡 Launching shard ${shard.id}`); console.log(`🟡 Launching shard ${shard.id}`);
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`)); shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
}) })
@@ -76,6 +79,4 @@ somethingEvent.on(async () => {
error, error,
); );
} }
}); }, 5000);
somethingEvent.emit(undefined);
+1 -1
View File
@@ -1,4 +1,4 @@
{ {
"extends": "../../tsconfig.json", "extends": "../../tsconfig.json",
"include": ["src/**/*"] "include": ["src/**/*", "../core/src/blitzkit/supportedLocales.ts"]
} }