diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 7c3a8c6..2688b1a 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -21,7 +21,7 @@ import { ApplicationCommandType, ComponentType } from 'discord.js'; import type { CommandModule, Module } from '../structures/module'; import { match } from 'ts-pattern'; import { SernError } from '../structures/errors'; -import type { DefinitelyDefined } from '../../types/handler'; +import type { DefinedCommandModule, DefinedModule } from '../../types/handler'; import { CommandType, PluginType } from '../structures/enums'; import { errTap } from './observableHandling'; @@ -39,7 +39,7 @@ export function onReady(wrapper: Wrapper) { }); }), map(({ mod, absPath }) => { - return >{ + return { name: mod?.name ?? Files.fmtFileName(basename(absPath)), description: mod?.description ?? '...', ...mod, @@ -70,7 +70,7 @@ export function onReady(wrapper: Wrapper) { ( concat(ready$, processPlugins$) as Observable<{ - mod: DefinitelyDefined; + mod: DefinedCommandModule; cmdPluginsRes: { execute: Awaitable>; type: PluginType.Command; @@ -106,9 +106,7 @@ export function onReady(wrapper: Wrapper) { }); } -function registerModule( - mod: DefinitelyDefined, -): Result { +function registerModule(mod: DefinedModule): Result { const name = mod.name; return match(mod) .with({ type: CommandType.Text }, mod => { diff --git a/src/handler/events/userDefinedEventsHandling.ts b/src/handler/events/userDefinedEventsHandling.ts index 8a187f4..ba85f87 100644 --- a/src/handler/events/userDefinedEventsHandling.ts +++ b/src/handler/events/userDefinedEventsHandling.ts @@ -1,9 +1,9 @@ import { CommandType } from '../structures/enums'; -import { from, fromEvent, map, throwError } from 'rxjs'; +import { concatMap, from, fromEvent, map, of, throwError } from 'rxjs'; import { SernError } from '../structures/errors'; import { buildData, ExternalEventEmitters } from '../utilities/readFile'; import { controller } from '../sern'; -import type { DefinitelyDefined } from '../../types/handler'; +import type { DefinedModule, DefinitelyDefined } from '../../types/handler'; import type { Module } from '../structures/module'; import type Wrapper from '../structures/wrapper'; import type { EventModule } from '../structures/module'; @@ -14,7 +14,7 @@ import { isDiscordEvent, isExternalEvent, isSernEvent } from '../utilities/predi import type { SpreadParams } from '../../types/handler'; import { errTap } from './observableHandling'; -export function processCommandPlugins$>( +export function processCommandPlugins$( { client, sernEmitter }: Wrapper, { mod, absPath }: { mod: T; absPath: string }, ) { @@ -58,8 +58,8 @@ export function processEvents( ); const processPlugins$ = normalize$.pipe(map(mod => mod)); //for now, until i figure out what to do with how plugins are registered - const processAndLoadEvents$ = normalize$.pipe( - map(mod => { + const processAndLoadEvents$ = processPlugins$.pipe( + concatMap(mod => { return match(mod as EventModule) .when(isSernEvent, m => { if (wrapper.sernEmitter === undefined) { @@ -71,13 +71,13 @@ export function processEvents( m.execute as SpreadParams, ); }) - .when(isDiscordEvent, m => - fromEvent( + .when(isDiscordEvent, m => { + return fromEvent( wrapper.client, - mod.name!, + m.name!, m.execute as SpreadParams, - ), - ) + ); + }) .when(isExternalEvent, m => { if (!ExternalEventEmitters.has(m.emitter)) { throw Error( diff --git a/src/handler/structures/events.ts b/src/handler/structures/events.ts index f2e008e..88fc4e3 100644 --- a/src/handler/structures/events.ts +++ b/src/handler/structures/events.ts @@ -9,7 +9,6 @@ import type { import type { CommandType } from './enums'; import type { SernEventsMapping } from '../sernEmitter'; import type { Awaitable, ClientEvents } from 'discord.js'; -import type { EventEmitter } from 'events'; export type SernEventCommand = Override< diff --git a/src/handler/structures/wrapper.ts b/src/handler/structures/wrapper.ts index ff13ded..ea854e8 100644 --- a/src/handler/structures/wrapper.ts +++ b/src/handler/structures/wrapper.ts @@ -1,5 +1,4 @@ import type { Client } from 'discord.js'; -import type { DiscordEvent, EventEmitterRegister, SernEvent } from '../../types/handler'; import type SernEmitter from '../sernEmitter'; import type { EventModule } from './module'; diff --git a/src/types/handler.ts b/src/types/handler.ts index fa1c0d7..4cd9431 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -1,4 +1,5 @@ import type { CommandInteractionOptionResolver } from 'discord.js'; +import type { CommandModule, Module } from '../handler/structures/module'; export type Nullish = T | undefined | null; // Thanks to @kelsny @@ -32,3 +33,10 @@ type IsOptional = { export type SpreadParams unknown> = ( args: Parameters[number], ) => unknown; + +/** + * After modules are transformed, name and description are given default values if none + * are provided to Module. This type represents that transformation + */ +export type DefinedModule = DefinitelyDefined; +export type DefinedCommandModule = DefinitelyDefined;