feat(handler): progress on event plugins

This commit is contained in:
Jacob Nguyen
2022-05-07 00:19:29 -05:00
parent 4448d5a1be
commit 2f61399b5e
3 changed files with 24 additions and 17 deletions

View File

@@ -1,10 +1,12 @@
import type { Interaction } from 'discord.js';
import { fromEvent, Observable, of, concatMap, map, tap } from 'rxjs';
import { ApplicationCommandType, Interaction } from 'discord.js';
import { fromEvent, Observable, of, concatMap, map, filter } from 'rxjs';
import { CommandType } from '../sern';
import Context from '../structures/context';
import type Wrapper from '../structures/wrapper';
import * as Files from '../utilities/readFile';
import { match, partition } from './observableHandling';
import { isEventPlugin } from './readyEvent';
@@ -12,20 +14,27 @@ import * as Files from '../utilities/readFile';
export const onInteractionCreate = ( wrapper : Wrapper ) => {
const { client } = wrapper;
const interactionEvent = (<Observable<Interaction>> fromEvent(client, 'interactionCreate'))
const interactionEvent$ = (<Observable<Interaction>> fromEvent(client, 'interactionCreate'))
const processPlugins = <T extends keyof ModuleDefs>( plug : Observable<PluggedModule|undefined> ) => {
return plug
};
interactionEvent.pipe(
concatMap ( async interaction => {
const processCommand$ = interactionEvent$.pipe(
concatMap( interaction => {
if(interaction.isCommand()) {
return of(
Files.ApplicationCommandStore[interaction.commandType]
.get(interaction.commandName)).pipe(
)
return of( Files
.ApplicationCommandStore[interaction.commandType]
.get(interaction.commandName)
).pipe(
)
}
})
);
})
).subscribe()
/** concatMap (async interaction => {
if (interaction.isChatInputCommand()) {
return of(Files.Commands.get(interaction.commandName))

View File

@@ -21,7 +21,7 @@ export const onMessageCreate = (wrapper : Wrapper) => {
map(message => {
const [prefix, ...rest] = fmt(message, defaultPrefix);
return {
ctx : Context.wrap(message),
ctx : Context.wrap(message), //TODO : check for BothCommand
args : <Args>['text', rest],
mod : Files.ApplicationCommandStore[1].get(prefix)
?? Files.BothCommand.get(prefix)
@@ -31,7 +31,7 @@ export const onMessageCreate = (wrapper : Wrapper) => {
const ensureModuleType$ = processMessage$.pipe(
concatMap(payload => of(payload.mod)
.pipe(
filterCorrectModule(CommandType.Text),
filterCorrectModule(CommandType.Text), // fix for BothCommand
map( textCommand => ({ ...payload, mod : textCommand }))
)));

View File

@@ -2,15 +2,13 @@ import {concatMap, from, fromEvent, map, take,concat, skip, Observable, of,
import { basename } from 'path';
import * as Files from '../utilities/readFile';
import type Wrapper from '../structures/wrapper';
import type { ApplicationModules, HandlerCallback, MessageCompModules, ModDefs, ModuleCbs, ModuleHandlers, ModuleStates, ModuleType, StateMachine, TextCommandModules, ModuleHandler } from '../structures/modules/commands/moduleHandler';
import type { HandlerCallback, ModuleHandlers, ModuleStates, ModuleType} from '../structures/modules/commands/moduleHandler';
import { CommandType } from '../sern';
import { CommandPlugin, EventPlugin, PluginType, SernPlugin } from '../plugins/plugin';
import { match, partition } from './observableHandling';
import { Err, Ok, Result } from 'ts-results';
import type { PluggedModule } from '../structures/modules/module';
import type { Awaitable } from 'discord.js';
import { SernError } from '../structures/errors';
import type { ContextMenuMsg, ContextMenuUser, Module, SlashCommand } from '../structures/modules/commands/module';
export const onReady = ( wrapper : Wrapper ) => {