mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat(handler) add basic interaction handling and add error for not
detecting modules
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Awaitable, ChatInputCommandInteraction, Interaction } from "discord.js";
|
||||
import { map, filter, fromEvent, Observable, of, mergeMap, tap} from "rxjs";
|
||||
import { map, filter, fromEvent, Observable, of, mergeMap, tap, concatMap} from "rxjs";
|
||||
import { None, Some } from "ts-results";
|
||||
import { CommandType } from "../sern";
|
||||
import Context from "../structures/context";
|
||||
@@ -13,7 +13,7 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => {
|
||||
|
||||
(fromEvent(client, 'interactionCreate') as Observable<Interaction>)
|
||||
.pipe(
|
||||
mergeMap ( interaction => {
|
||||
concatMap ( interaction => {
|
||||
if (interaction.isChatInputCommand()) {
|
||||
return of(interaction.commandName).pipe(
|
||||
map ( Files.Commands.get ),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export enum SernError {
|
||||
RESERVED_EVENT = 'Cannot register the reserved ready event. Please use the init property.',
|
||||
NO_ALIAS = 'You cannot provide an array with elements to a slash command.',
|
||||
NOT_VALID_MOD_TYPE = 'Detected an unknown module type'
|
||||
NOT_VALID_MOD_TYPE = 'Detected an unknown module type',
|
||||
UNDEFINED_MODULE = `A module could not be detected at`
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { ApplicationCommandOptionData } from 'discord.js';
|
||||
import { readdirSync, statSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import type { Module } from '../structures/commands/module';
|
||||
import { SernError } from '../structures/errors';
|
||||
|
||||
|
||||
export const Commands = new Map<string, Module>();
|
||||
@@ -39,7 +40,9 @@ export async function buildData(commandDir: string ): Promise<
|
||||
> {
|
||||
return Promise.all(
|
||||
getCommands(commandDir).map( async (absPath) => {
|
||||
return { mod: (await import(absPath)).module as Module, absPath };
|
||||
const mod = (await import(absPath)).module as Module;
|
||||
if (mod === undefined) throw Error(`${SernError.UNDEFINED_MODULE} ${absPath}`)
|
||||
return { mod, absPath };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user