fix: lang handler (#213)

This commit is contained in:
Marcos Susaña 2024-06-24 15:17:15 -04:00 committed by GitHub
parent 1cb4ab4a46
commit 6547f71b1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View File

@ -223,7 +223,6 @@ export class BaseClient {
this.langs = undefined;
} else if (typeof handlers.langs === 'function') {
this.langs ??= new LangsHandler(this.logger);
this.langs.setHandlers({ callback: handlers.langs });
} else {
this.langs = handlers.langs;
}
@ -492,7 +491,7 @@ export interface ServicesOptions {
handlers?: {
components?: ComponentHandler | ComponentHandler['callback'];
commands?: CommandHandler;
langs?: LangsHandler | LangsHandler['callback'];
langs?: LangsHandler;
};
handleCommand?: typeof HandleCommand;
}

View File

@ -1,6 +1,7 @@
import type { Locale, LocaleString } from 'discord-api-types/v10';
import { BaseHandler } from '../common';
import { LangRouter } from './router';
import type { FileLoaded } from '../commands/handler';
export class LangsHandler extends BaseHandler {
values: Partial<Record<string, any>> = {};
@ -40,14 +41,12 @@ export class LangsHandler extends BaseHandler {
const files = instances ?? (await this.loadFilesK<Record<string, any>>(await this.getFiles(dir)));
for (const i of files) {
const locale = i.name.split('.').slice(0, -1).join('.') || i.name;
const result = this.callback(locale, i.file);
const result = this.onFile(locale, i.file);
if (result) this.values[locale] = result;
}
}
setHandlers({ callback }: { callback: LangsHandler['callback'] }) {
this.callback = callback;
onFile(_locale: string, file: FileLoaded<Record<string, any>>): Record<string, any> | false {
return file.default ?? false;
}
callback = (_locale: string, file: Record<string, any>): Record<string, any> | false => file;
}