From fc08ae4c79ad1d19a8844b645043ea5a609bc0fb Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 20 Apr 2022 19:39:59 -0500 Subject: [PATCH] fix(readyEvent) : module loading not correctly. --- src/handler/events/messageEvent.ts | 24 +++++++++++++++++------- src/handler/events/observableHandling.ts | 1 + src/handler/events/readyEvent.ts | 22 +++++++++++----------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index 2adf4fa..d236129 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -1,8 +1,7 @@ import type { Message } from 'discord.js'; -import { fromEvent, Observable, of, concatMap, mergeMap, map, from, every, concatAll, concat } from 'rxjs'; +import { fromEvent, Observable, of, concatMap, mergeMap, map, from, every, concatAll, concat, tap } from 'rxjs'; import { Err, Ok } from 'ts-results'; import type { Args } from '../..'; -import type { EventPlugin } from '../plugins/plugin'; import { CommandType } from '../sern'; import Context from '../structures/context'; import type Wrapper from '../structures/wrapper'; @@ -18,6 +17,7 @@ export const onMessageCreate = (wrapper : Wrapper) => { ignoreNonBot(defaultPrefix), map(message => { const [prefix, ...rest] = fmt(message, defaultPrefix); + console.log(prefix, rest) return { ctx : Context.wrap(message), args : ['text', rest], @@ -27,13 +27,14 @@ export const onMessageCreate = (wrapper : Wrapper) => { const ensureModuleType$ = processMessage$.pipe( concatMap(payload => of(payload.mod) .pipe( + tap(console.log), filterCorrectModule(CommandType.Text), - map( textCommand => ({ ...payload, textCommand })) + map( textCommand => ({ ...payload, mod : textCommand })) ))); const processPlugins$ = ensureModuleType$.pipe( - mergeMap( ({ctx, args, textCommand}) => { - const res = from(textCommand.plugins.map(ePlug => { - return from((ePlug).execute([ctx, args], { + mergeMap( ({ctx, args, mod}) => { + const res = from(mod.plugins.map(ePlug => { + return from((ePlug).execute([ctx, args], { next : () => Ok.EMPTY, stop : () => Err.EMPTY })) @@ -41,5 +42,14 @@ export const onMessageCreate = (wrapper : Wrapper) => { return res.pipe(concatAll(), every(res => res.ok)) }) ); - + ensureModuleType$.pipe( + concatMap( pl => { + return processPlugins$.pipe( + map ( res => ({ res, pl })) + ) + }) + ).subscribe( ({ res, pl }) => { + console.log('test') + console.log(res, pl) + }) }; diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index 3b1a47c..f37308b 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -19,6 +19,7 @@ export function filterCorrectModule(cmdType : T) { new Observable<{ mod : ModuleDefs[T], plugins : EventPlugin[] }>( subscriber => { return src.subscribe({ next(plug) { + console.log(plug) if(match(plug, cmdType)) { subscriber.next({ mod : plug.mod, plugins : plug.plugins }); } else { diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index c296634..cfef13b 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -1,4 +1,4 @@ -import { from, fromEvent, map, take,concat, concatAll, mergeMap, skip, Observable} from 'rxjs'; +import { from, fromEvent, map, take,concat, concatAll, mergeMap, skip, Observable, tap} from 'rxjs'; import { basename } from 'path'; import * as Files from '../utilities/readFile'; import type Wrapper from '../structures/wrapper'; @@ -12,16 +12,15 @@ import type { PluggedModule } from '../structures/modules/module'; export const onReady = ( wrapper : Wrapper ) => { const { client, commands } = wrapper; const ready$ = fromEvent(client, 'ready').pipe(take(1),skip(1)); - const processCommandFiles$ = from(Files.buildData(commands)).pipe( - concatAll(), + const processCommandFiles$ = Files.buildData(commands).pipe( map(({plugged, absPath}) => { const name = plugged.mod?.name ?? Files.fmtFileName(basename(absPath)); if (plugged.mod?.name === undefined ) { return { mod: { name, ...plugged.mod }, plugins : plugged.plugins }; } return plugged; - }), - mergeMap(({ mod, plugins: allPlugins }) => { + })); + /** mergeMap(({ mod, plugins: allPlugins }) => { const [ cmdPlugins, plugins ] = partition(allPlugins, isCmdPlugin); return cmdPlugins.map(pl => { const res = pl.execute(client, mod, { @@ -31,13 +30,13 @@ export const onReady = ( wrapper : Wrapper ) => { return { res, plugged : { mod, plugins } } }) }) - ); - - (concat(ready$,processCommandFiles$) as Observable<{ - res : Promise>, plugged : PluggedModule - }>) - .subscribe( + **/ + (concat(ready$,processCommandFiles$) as Observable< + PluggedModule + >) + .subscribe(console.log) + /** ({ res, plugged: { mod, plugins }}) => { res.then( result => { if(result.ok) { @@ -51,6 +50,7 @@ export const onReady = ( wrapper : Wrapper ) => { } }); }) + **/ }