mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: allow constructable modules (#133)
* Update readFile.ts * Update userDefinedEventsHandling.ts * Update readyHandler.ts * fix: ts error Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Co-authored-by: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com>
This commit is contained in:
@@ -87,7 +87,7 @@ export default class ReadyHandler extends EventsHandler<{
|
||||
type: PluginType.Command;
|
||||
}[];
|
||||
}) {
|
||||
if (mod.plugins.length === 0) {
|
||||
if ((mod.plugins || []).length === 0) {
|
||||
return of({ mod, pluginRes: [] });
|
||||
}
|
||||
// modules with no event plugins are ignored in the previous
|
||||
|
||||
@@ -25,7 +25,7 @@ export function processCommandPlugins<T extends DefinedCommandModule>(
|
||||
wrapper: Wrapper,
|
||||
payload: { mod: T; absPath: string },
|
||||
) {
|
||||
return payload.mod.plugins.map(plug => ({
|
||||
return (payload.mod.plugins || []).map(plug => ({
|
||||
...plug,
|
||||
name: plug?.name ?? 'Unnamed Plugin',
|
||||
description: plug?.description ?? '...',
|
||||
|
||||
@@ -73,6 +73,11 @@ export function buildData<T>(commandDir: string): Observable<
|
||||
} catch {
|
||||
mod = (await import(`file:///` + absPath)).default;
|
||||
}
|
||||
|
||||
try {
|
||||
mod = new (mod as unknown as new (...args: unknown[]) => T)();
|
||||
} catch {}
|
||||
|
||||
if (mod !== undefined) {
|
||||
return Ok({ mod, absPath });
|
||||
} else return Err(SernError.UndefinedModule);
|
||||
|
||||
Reference in New Issue
Block a user