mirror of
https://github.com/sern-handler/handler
synced 2026-06-17 21:32:14 +00:00
feat(handler) added module type checking and started interactions handler
This commit is contained in:
27
src/handler/events/interactionCreate.ts
Normal file
27
src/handler/events/interactionCreate.ts
Normal 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(
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -112,7 +112,6 @@ export class Handler {
|
||||
/**
|
||||
* @enum { number };
|
||||
*/
|
||||
|
||||
export enum CommandType {
|
||||
TEXT = 0b0001,
|
||||
SLASH = 0b0010,
|
||||
|
||||
Reference in New Issue
Block a user