diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 033c7f6..078eb94 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -28,7 +28,7 @@ import { errTap } from './observableHandling'; export const onReady = (wrapper: Wrapper) => { const { client, commands } = wrapper; const ready$ = fromEvent(client, 'ready').pipe(take(1), skip(1)); - const processCommandFiles$ = Files.buildData(commands).pipe( + const processCommandFiles$ = Files.buildData(commands).pipe( errTap(reason => { wrapper.sernEmitter?.emit('module.register', { type: 'failure', diff --git a/src/handler/structures/wrapper.ts b/src/handler/structures/wrapper.ts index 2343940..c110dff 100644 --- a/src/handler/structures/wrapper.ts +++ b/src/handler/structures/wrapper.ts @@ -16,7 +16,10 @@ interface Wrapper { readonly sernEmitter?: SernEmitter; readonly defaultPrefix?: string; readonly commands: string; - readonly events?: (DiscordEvent | EventEmitterRegister | SernEvent)[]; + readonly events?: + | (DiscordEvent | EventEmitterRegister | SernEvent)[] + | string + | (() => (DiscordEvent | EventEmitterRegister | SernEvent)[]); } export default Wrapper; diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index d7591fe..74bbd22 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -48,10 +48,10 @@ export const fmtFileName = (n: string) => n.substring(0, n.length - 3); * @param commandDir */ -export function buildData(commandDir: string): Observable< +export function buildData(commandDir: string): Observable< Result< { - mod: Module; + mod: T; absPath: string; }, SernError.UndefinedModule @@ -60,7 +60,7 @@ export function buildData(commandDir: string): Observable< return from( getCommands(commandDir).map(absPath => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const mod = require(absPath).default; + const mod = require(absPath).default; if (mod !== undefined) { return Ok({ mod, absPath }); } else return Err(SernError.UndefinedModule as const);