diff --git a/src/handler/events/readyHandler.ts b/src/handler/events/readyHandler.ts index 1a5318e5..83e02dcf 100644 --- a/src/handler/events/readyHandler.ts +++ b/src/handler/events/readyHandler.ts @@ -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 diff --git a/src/handler/events/userDefinedEventsHandling.ts b/src/handler/events/userDefinedEventsHandling.ts index fa02698c..5293520e 100644 --- a/src/handler/events/userDefinedEventsHandling.ts +++ b/src/handler/events/userDefinedEventsHandling.ts @@ -25,7 +25,7 @@ export function processCommandPlugins( 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 ?? '...', diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index 1f12eeef..47497bf8 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -73,6 +73,11 @@ export function buildData(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);