From 269ab563ab2e8259c0482fa221a9508ef02daff3 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 15 May 2022 19:26:38 -0500 Subject: [PATCH] refactor: Cleaning up --- src/handler/events/interactionCreate.ts | 1 - src/handler/events/messageEvent.ts | 1 - src/handler/events/observableHandling.ts | 27 +----------------------- src/handler/events/readyEvent.ts | 20 +++++++++--------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 03944d9..86f4ec2 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -30,7 +30,6 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command return throwError(() => SernError.UndefinedModule); } const eventPlugins = mod.onEvent; - return match(interaction) .when(isChatInputCommand, i => { const ctx = Context.wrap(i); diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index 9771dd6..bac6f12 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -23,7 +23,6 @@ export const onMessageCreate = (wrapper: Wrapper) => { ctx: Context.wrap(message), //TODO : check for BothCommand args: ['text', rest], mod: - Files.ApplicationCommands[1].get(prefix) ?? Files.BothCommands.get(prefix) ?? Files.TextCommands.aliases.get(prefix), }; diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index 2a61009..72793a9 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -31,34 +31,9 @@ export function filterCorrectModule(cmdType: T) { }); } -/** export function filterTap( - cmdType : T, - tap: (mod : ModuleDefs[T], plugins : EventPlugin[]) => Awaitable - ) { - return (src : Observable) => - new Observable( subscriber => { - return src.subscribe({ - next(modul) { - if(match(modul, cmdType)) { - const asModT = modul!.mod; - tap(asModT, modul!.plugins as EventPlugin[]); - subscriber.next(modul); - } else { - if (modul === undefined) { - return throwError(() => SernError.UndefinedModule); - } - return throwError(() => SernError.MismatchModule); - } - }, - error: (e) => subscriber.error(e), - complete: () => subscriber.complete() - }); - }); - } - **/ export function ignoreNonBot(prefix: string) { return (src: Observable) => - new Observable(subscriber => { + new Observable(subscriber => { return src.subscribe({ next(m) { const passAll = [ diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 31d263d..070a8c6 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -7,7 +7,7 @@ import type { PluginType } from '../plugins/plugin'; import type { Result } from 'ts-results'; import type { Awaitable } from 'discord.js'; import type { Module } from '../structures/module'; -import { match, P } from 'ts-pattern'; +import { match } from 'ts-pattern'; import { ApplicationCommandType, ComponentType } from 'discord.js'; export const onReady = (wrapper: Wrapper) => { @@ -64,30 +64,30 @@ export const onReady = (wrapper: Wrapper) => { }); }; -function registerModule(mod : Module) { +function registerModule(mod: Module) { const name = mod.name!; match(mod) - .with({type : CommandType.Text }, mod => { + .with({ type: CommandType.Text }, mod => { mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod)); Files.TextCommands.text.set(name, mod); }) - .with({ type : CommandType.Slash }, mod => { + .with({ type: CommandType.Slash }, mod => { Files.ApplicationCommands[ApplicationCommandType.ChatInput].set(name, mod); }) - .with( { type : CommandType.Both }, mod => { + .with({ type: CommandType.Both }, mod => { Files.BothCommands.set(name, mod); mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod)); }) - .with( { type : CommandType.MenuUser }, mod => { + .with({ type: CommandType.MenuUser }, mod => { Files.ApplicationCommands[ApplicationCommandType.User].set(name, mod); }) - .with( { type : CommandType.MenuMsg }, mod => { + .with({ type: CommandType.MenuMsg }, mod => { Files.ApplicationCommands[ApplicationCommandType.Message].set(name, mod); }) - .with( { type : CommandType.Button }, mod => { + .with({ type: CommandType.Button }, mod => { Files.ApplicationCommands[ComponentType.Button].set(name, mod); }) - .with( { type: CommandType.MenuSelect }, mod => { + .with({ type: CommandType.MenuSelect }, mod => { Files.MessageCompCommands[ComponentType.SelectMenu].set(name, mod); - }) + }); }