mirror of
https://github.com/sern-handler/handler
synced 2026-06-15 12:22:14 +00:00
fix(readyEvent) : module loading not correctly.
This commit is contained in:
@@ -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 : <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((<EventPlugin>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)
|
||||
})
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ export function filterCorrectModule<T extends keyof ModuleDefs>(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 : <EventPlugin[]>plug.plugins });
|
||||
} else {
|
||||
|
||||
@@ -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 : <PluggedModule>{ mod, plugins } }
|
||||
})
|
||||
})
|
||||
);
|
||||
|
||||
(concat(ready$,processCommandFiles$) as Observable<{
|
||||
res : Promise<Result<void, void>>, 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 ) => {
|
||||
}
|
||||
});
|
||||
})
|
||||
**/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user