diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 610f8c6..7dc6c58 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -1,15 +1,16 @@ -import { ApplicationCommandType, Interaction } from 'discord.js'; -import { fromEvent, Observable, of, concatMap, map, filter } from 'rxjs'; +import { ApplicationCommandType, ChatInputCommandInteraction, Interaction } from 'discord.js'; +import { fromEvent, Observable, of, concatMap, map, filter, throwError } from 'rxjs'; import { CommandType } from '../sern'; import Context from '../structures/context'; import type { ModuleDefs } from '../structures/modules/commands/moduleHandler'; import type { PluggedModule } from '../structures/modules/module'; import type Wrapper from '../structures/wrapper'; import * as Files from '../utilities/readFile'; -import { match, partition } from './observableHandling'; +import { match } from 'ts-pattern'; import { isEventPlugin } from './readyEvent'; - +import { _ } from 'ts-pattern/dist/patterns'; +import { SernError } from '../structures/errors'; @@ -19,18 +20,32 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { const interactionEvent$ = (> fromEvent(client, 'interactionCreate')) - const processCommand$ = interactionEvent$.pipe( + interactionEvent$.pipe( concatMap( interaction => { if(interaction.isCommand()) { return of( Files .ApplicationCommandStore[interaction.commandType] .get(interaction.commandName) - ).pipe( + ).pipe( + map ( plug => { + if(plug === undefined) { + return throwError(() => SernError.UndefinedModule) + } + const eventPlugins = plug.plugins.filter(isEventPlugin); + match(interaction) + .when( interaction.isChatInputCommand, (i : ChatInputCommandInteraction) => { + console.log(i, eventPlugins) + }) + .when( () => _ , i => { + console.log(i, eventPlugins) + }) + return "fsd" + }) ) - } + return of() }) - ); + ).subscribe(); diff --git a/src/handler/sern.ts b/src/handler/sern.ts index bb5cc9a..08e81e4 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -13,6 +13,8 @@ import { SernError } from './structures/errors'; import { onReady } from './events/readyEvent'; import { onMessageCreate } from './events/messageEvent'; import { onInteractionCreate } from './events/interactionCreate'; +import { match } from 'ts-pattern'; +import { _ } from 'ts-pattern/dist/patterns'; export function init( wrapper : Wrapper ) { const { events, client } = wrapper; @@ -44,12 +46,12 @@ export enum CommandType { } export function cmdTypeToDjs(ty: CommandType) { - switch (ty) { - case CommandType.Slash : case CommandType.Both : return ApplicationCommandType.ChatInput; - case CommandType.MenuUser : return ApplicationCommandType.User; - case CommandType.MenuMsg : return ApplicationCommandType.Message; - default : throw new Error(`Cannot turn this CommandType to ApplicationCommandType`) - } + return match(ty) + .with(CommandType.Slash, () => ApplicationCommandType.ChatInput) + .with(CommandType.MenuUser, () => ApplicationCommandType.User) + .with(CommandType.MenuMsg, ()=> ApplicationCommandType.Message) + .with(_, () => { throw new Error(SernError.NonValidModuleType) }) + .exhaustive() }