mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
Merge branch 'main' into dev
This commit is contained in:
commit
1d44ecab18
8 files changed
+49
-30
No files matched your search
@@ -113,6 +113,9 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Lint
|
||||
run: bun run lint:website
|
||||
|
||||
- name: Download depots
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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';
|
||||
|
||||
const validNameRegex = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
|
||||
@@ -9,7 +9,7 @@ export function localizationObject(
|
||||
literals?: string[],
|
||||
strict = false,
|
||||
) {
|
||||
return SUPPORTED_DISCORD_LOCALES.reduce<Partial<Record<Locale, string>>>(
|
||||
return SUPPORTED_LOCALES_DISCORD.reduce<Partial<Record<Locale, string>>>(
|
||||
(localizations, locale) => {
|
||||
const { translate } = translator(locale);
|
||||
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';
|
||||
|
||||
const DISCORD_SUPPORTED_LOCALES: Record<SupportedLocale, Locale> = {
|
||||
const SUPPORTED_LOCALES_DISCORD_MAP: Record<SupportedLocale, Locale> = {
|
||||
en: Locale.EnglishUS,
|
||||
es: Locale.SpanishES,
|
||||
hr: Locale.Croatian,
|
||||
@@ -11,6 +11,13 @@ const DISCORD_SUPPORTED_LOCALES: Record<SupportedLocale, Locale> = {
|
||||
zh: Locale.ChineseCN,
|
||||
};
|
||||
|
||||
export const SUPPORTED_DISCORD_LOCALES = Object.values(
|
||||
DISCORD_SUPPORTED_LOCALES,
|
||||
export const SUPPORTED_LOCALES_DISCORD_MAP_INVERSE = Object.fromEntries(
|
||||
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 { SUPPORTED_DISCORD_LOCALES } from './constants';
|
||||
import {
|
||||
SUPPORTED_LOCALES_DISCORD,
|
||||
SUPPORTED_LOCALES_DISCORD_MAP_INVERSE,
|
||||
} from './constants';
|
||||
|
||||
export type TranslationFragmentTree = {
|
||||
[key: string]: TranslationFragment;
|
||||
@@ -8,12 +11,14 @@ export type TranslationFragmentTree = {
|
||||
};
|
||||
export type TranslationFragment = string | TranslationFragmentTree;
|
||||
|
||||
export const translations = SUPPORTED_DISCORD_LOCALES.reduce<
|
||||
export const translations = SUPPORTED_LOCALES_DISCORD.reduce<
|
||||
Partial<Record<Locale, TranslationFragment>>
|
||||
>(
|
||||
(table, locale) => ({
|
||||
...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 { 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) {
|
||||
const locale =
|
||||
localeRaw !== Locale.EnglishUS &&
|
||||
SUPPORTED_DISCORD_LOCALES.includes(localeRaw)
|
||||
localeRaw !== DEFAULT_LOCALE_DISCORD &&
|
||||
SUPPORTED_LOCALES_DISCORD.includes(localeRaw)
|
||||
? localeRaw
|
||||
: Locale.EnglishUS;
|
||||
: DEFAULT_LOCALE_DISCORD;
|
||||
const strings = translations[locale]!;
|
||||
|
||||
function translate(path: string, literals?: string[]): string {
|
||||
@@ -26,11 +29,11 @@ export function translator(localeRaw: Locale) {
|
||||
if (typeof fragment === 'undefined') {
|
||||
const message = `Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"`;
|
||||
|
||||
if (locale === Locale.EnglishUS) {
|
||||
if (locale === DEFAULT_LOCALE_DISCORD) {
|
||||
throw new Error(message);
|
||||
} else {
|
||||
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
@@ -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 {
|
||||
discoveredIdsDefinitions,
|
||||
tankDefinitions,
|
||||
} 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', {
|
||||
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
|
||||
.on('shardCreate', (shard) => {
|
||||
clearTimeout(timeout);
|
||||
clearInterval(interval);
|
||||
console.log(`🟡 Launching shard ${shard.id}`);
|
||||
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
||||
})
|
||||
@@ -76,6 +79,4 @@ somethingEvent.on(async () => {
|
||||
error,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
somethingEvent.emit(undefined);
|
||||
}, 5000);
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*"]
|
||||
"include": ["src/**/*", "../core/src/blitzkit/supportedLocales.ts"]
|
||||
}
|
||||
Reference in new issue
Block a user