From e69dae92cda1f22ea09e366d61e091a716eeca7e Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Fri, 27 May 2022 15:06:24 -0500 Subject: [PATCH] refactor: cleaning up code, removing unuseds --- src/handler/events/interactionCreate.ts | 2 +- src/handler/events/observableHandling.ts | 14 +++++++++++++- src/handler/structures/errors.ts | 4 ---- src/handler/structures/module.ts | 13 +++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 22bbeab..bc1421b 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -206,7 +206,7 @@ export function onInteractionCreate(wrapper: Wrapper) { Files.BothCommands.get(interaction.commandName); return autoCmpHandler(modul, interaction); } - return of(); + return throwError(() => SernError.NotSupportedInteraction); }), ) .subscribe({ diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index ba3d552..9449f49 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -1,8 +1,9 @@ import type { Message } from 'discord.js'; import { Observable, throwError } from 'rxjs'; import { SernError } from '../structures/errors'; -import type { Module, ModuleDefs } from '../structures/module'; +import type { InteractionDefs, Module, ModuleDefs } from '../structures/module'; import { correctModuleType } from '../utilities/predicates'; +import type { CommandType } from '../structures/enums'; export function filterCorrectModule(cmdType: T) { return (src: Observable) => @@ -43,3 +44,14 @@ export function ignoreNonBot(prefix: string) { }); }); } + +export function processOnEvents(interaction: InteractionDefs[T]) { + return (src: Observable) => + new Observable(subscriber => { + return src.subscribe({ + next(m) {}, + error: e => subscriber.error(e), + complete: () => subscriber.complete(), + }); + }); +} diff --git a/src/handler/structures/errors.ts b/src/handler/structures/errors.ts index 82d2f9c..f95f2cf 100644 --- a/src/handler/structures/errors.ts +++ b/src/handler/structures/errors.ts @@ -1,11 +1,7 @@ export enum SernError { - ReservedEvent = 'Cannot register the reserved ready event. Please use the init property.', - NoAlias = 'You cannot provide an array with elements to a slash command.', NonValidModuleType = 'Detected an unknown module type', UndefinedModule = `A module could not be detected at`, MismatchModule = `A module type mismatched with event emitted!`, - NotImplemented = 'This feature has not yet been implemented', NotSupportedInteraction = `This interaction is not supported.`, - NotValidEventName = `Supplied a non valid event name`, PluginFailure = `A plugin failed to call controller.next()`, } diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index 20ded25..d6b862d 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -21,6 +21,7 @@ import type Context from './context'; import { CommandType, PluginType } from './enums'; import type { AutocompleteInteraction } from 'discord.js'; import type { ApplicationCommandOptionType } from 'discord.js'; +import { ChatInputCommandInteraction, Message } from 'discord.js'; export interface BaseModule { type: CommandType | PluginType; @@ -150,6 +151,18 @@ export type ModuleDefs = { [CommandType.Autocomplete]: AutocompleteCommand; }; +export type InteractionDefs = { + [CommandType.Text]: Context; + [CommandType.Slash]: Context; + [CommandType.Both]: Context; + [CommandType.MenuMsg]: MessageContextMenuCommandInteraction; + [CommandType.MenuUser]: UserContextMenuCommandInteraction; + [CommandType.Button]: ButtonInteraction; + [CommandType.MenuSelect]: SelectMenuInteraction; + [CommandType.Modal]: ModalSubmitInteraction; + [CommandType.Autocomplete]: AutocompleteInteraction; +}; + //TODO: support deeply nested Autocomplete // objective: construct union of ApplicationCommandOptionData change any Autocomplete data // into Sern autocomplete data.