feat(handler) added module type checking and started interactions handler

This commit is contained in:
Jacob Nguyen
2022-03-20 14:49:14 -05:00
parent 1ad429fb5f
commit 99aae7d780
4 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,27 @@
import type { CommandInteraction, Interaction } from "discord.js";
import { map, filter, fromEvent, Observable, of, concatMap } from "rxjs";
import { None, Some } from "ts-results";
import Context from "../structures/context";
import type Wrapper from "../structures/wrapper";
import { isNotFromDM, isNotFromBot, hasPrefix, fmt } from "../utilities/messageHelpers";
import * as Files from '../utilities/readFile';
export const onInteractionCreate = ( wrapper : Wrapper ) => {
const { client } = wrapper;
(fromEvent(client, 'interactionCreate') as Observable<Interaction>)
.pipe(
)
}

View File

@@ -1,6 +1,7 @@
import type { Message } from "discord.js";
import { map, filter, fromEvent, Observable, of, concatMap, tap } from "rxjs";
import { map, filter, fromEvent, Observable, of, concatMap } from "rxjs";
import { None, Some } from "ts-results";
import { CommandType } from "../sern";
import Context from "../structures/context";
import type Wrapper from "../structures/wrapper";
import { isNotFromDM, isNotFromBot, hasPrefix, fmt } from "../utilities/messageHelpers";
@@ -18,7 +19,7 @@ export const onMessageCreate = (wrapper : Wrapper) => {
map(([prefix, ...args ]) =>{
return [Files.Commands.get(prefix) ?? Files.Alias.get(prefix), new Context(Some(m), None), args ] as const;
}),
filter( ([mod]) => mod !== undefined),
filter( ([mod]) => mod !== undefined && (mod.type & CommandType.TEXT) != 0 ),
map ( async ([ mod, ctx, args ]) => {
const parsedArgs = mod!.parse?.(ctx, args);
const res = await mod!.execute(ctx, parsedArgs);

View File

@@ -40,7 +40,7 @@ const handler = ( name : string ) =>
Files.Commands.set ( name, mod);
mod.alias.forEach (a => Files.Alias.set(a, mod));
}
}) as ModuleHandlers;
} as ModuleHandlers);
const registerModules = <T extends ModuleType >(name : string, mod : ModuleStates[T]) =>
(handler(name)[mod.type] as HandlerCallback<T>)(mod);

View File

@@ -112,7 +112,6 @@ export class Handler {
/**
* @enum { number };
*/
export enum CommandType {
TEXT = 0b0001,
SLASH = 0b0010,