feat: migrate to bun

This commit is contained in:
TrèsAbhi committed 2024-07-20 20:36:36 -05:00
1 parent 6ecabe1d77
commit 9ffd20ffbf
10 files changed
+35 -45

No files matched your search

+3 -4
View File
@@ -1,10 +1,9 @@
import { Worker } from 'worker_threads';
const MAX_WORKERS = 2;
const RENDER_WORKERS = 1;
const workers = [...Array(MAX_WORKERS)].map(() => {
// const worker = new Worker('src/workers/render.ts');
const worker = new Worker(`${__dirname}/workers/render.cjs`);
const workers = [...Array(RENDER_WORKERS)].map(() => {
const worker = new Worker('dist/bot/workers/render.js');
console.log(`🟡 Launching render worker ${worker.threadId}`);
return worker;
});
+1 -1
View File
@@ -1,6 +1,6 @@
import { ShardingManager } from 'discord.js';
import { secrets } from '../blitzkit/secrets';
export const manager = new ShardingManager(`${__dirname}/bot.cjs`, {
export const manager = new ShardingManager('dist/bot/workers/bot.js', {
token: secrets.DISCORD_TOKEN,
});
+1 -1
View File
@@ -1,3 +1,3 @@
import { Locale } from 'discord.js';
export const SUPPORTED_LOCALES: Locale[] = [Locale.SpanishES];
export const SUPPORTED_LOCALES: Locale[] = [Locale.EnglishUS, Locale.SpanishES];
+7 -11
View File
@@ -1,5 +1,4 @@
import { Locale } from 'discord.js';
import enUS from '../../../lang/en-US.json';
import { SUPPORTED_LOCALES } from './constants';
export type TranslationFragmentTree = {
@@ -9,15 +8,12 @@ export type TranslationFragmentTree = {
};
export type TranslationFragment = string | TranslationFragmentTree;
export const translations = SUPPORTED_LOCALES.map((locale) => ({
locale,
translations: require(`../../../lang/${locale}.json`),
})).reduce(
(table, { locale, translations }) => ({
export const translations = SUPPORTED_LOCALES.reduce<
Partial<Record<Locale, TranslationFragment>>
>(
(table, locale) => ({
...table,
[locale]: translations,
[locale]: require(`../lang/${locale}.json`),
}),
{
[Locale.EnglishUS]: enUS,
},
) as Partial<Record<Locale, TranslationFragment>>;
{},
);
+4 -6
View File
@@ -23,14 +23,12 @@ export function translator(localeRaw: Locale) {
fragment = fragment[pathItem];
if (typeof fragment === 'undefined') {
const message = `Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"`;
if (locale === Locale.EnglishUS) {
throw new Error(
`Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"`,
);
throw new Error(message);
} else {
console.warn(
`Undefined translation at "${pathItem}" in "${path}" for locale "${locale}"; falling back to en-US`,
);
console.warn(`${message} falling back to en-US`);
return translator(Locale.EnglishUS).translate(path, literals);
}
}