mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
fix: lang handler (#213)
This commit is contained in:
parent
1cb4ab4a46
commit
6547f71b1f
@ -223,7 +223,6 @@ export class BaseClient {
|
|||||||
this.langs = undefined;
|
this.langs = undefined;
|
||||||
} else if (typeof handlers.langs === 'function') {
|
} else if (typeof handlers.langs === 'function') {
|
||||||
this.langs ??= new LangsHandler(this.logger);
|
this.langs ??= new LangsHandler(this.logger);
|
||||||
this.langs.setHandlers({ callback: handlers.langs });
|
|
||||||
} else {
|
} else {
|
||||||
this.langs = handlers.langs;
|
this.langs = handlers.langs;
|
||||||
}
|
}
|
||||||
@ -492,7 +491,7 @@ export interface ServicesOptions {
|
|||||||
handlers?: {
|
handlers?: {
|
||||||
components?: ComponentHandler | ComponentHandler['callback'];
|
components?: ComponentHandler | ComponentHandler['callback'];
|
||||||
commands?: CommandHandler;
|
commands?: CommandHandler;
|
||||||
langs?: LangsHandler | LangsHandler['callback'];
|
langs?: LangsHandler;
|
||||||
};
|
};
|
||||||
handleCommand?: typeof HandleCommand;
|
handleCommand?: typeof HandleCommand;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import type { Locale, LocaleString } from 'discord-api-types/v10';
|
import type { Locale, LocaleString } from 'discord-api-types/v10';
|
||||||
import { BaseHandler } from '../common';
|
import { BaseHandler } from '../common';
|
||||||
import { LangRouter } from './router';
|
import { LangRouter } from './router';
|
||||||
|
import type { FileLoaded } from '../commands/handler';
|
||||||
|
|
||||||
export class LangsHandler extends BaseHandler {
|
export class LangsHandler extends BaseHandler {
|
||||||
values: Partial<Record<string, any>> = {};
|
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)));
|
const files = instances ?? (await this.loadFilesK<Record<string, any>>(await this.getFiles(dir)));
|
||||||
for (const i of files) {
|
for (const i of files) {
|
||||||
const locale = i.name.split('.').slice(0, -1).join('.') || i.name;
|
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;
|
if (result) this.values[locale] = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setHandlers({ callback }: { callback: LangsHandler['callback'] }) {
|
onFile(_locale: string, file: FileLoaded<Record<string, any>>): Record<string, any> | false {
|
||||||
this.callback = callback;
|
return file.default ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback = (_locale: string, file: Record<string, any>): Record<string, any> | false => file;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user