From bcbfd287880a5ddee73b4905acad814bfde875fe Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 15 May 2022 19:31:30 -0500 Subject: [PATCH] refactor: Cleaning up more, moving things for organization --- src/handler/events/interactionCreate.ts | 3 +-- src/handler/events/observableHandling.ts | 10 ++-------- src/handler/utilities/predicates.ts | 8 ++++++++ src/handler/utilities/resolveParameters.ts | 7 ------- src/types/handler.ts | 8 ++++++++ 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 src/handler/utilities/predicates.ts delete mode 100644 src/handler/utilities/resolveParameters.ts diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 86f4ec2..ff91b2b 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -13,10 +13,9 @@ import { SernError } from '../structures/errors'; import Context from '../structures/context'; import type { Result } from 'ts-results'; import { CommandType, controller } from '../sern'; -import type { Args } from '../../types/handler'; +import type { Args, UnionToTuple } from '../../types/handler'; import type { MessageComponentInteraction } from 'discord.js'; import { ComponentType } from 'discord.js'; -import type { UnionToTuple } from '../utilities/resolveParameters'; import type { Module } from '../structures/module'; import type { EventPlugin } from '../plugins/plugin'; diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index 72793a9..e61b331 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -3,13 +3,7 @@ import { Observable, throwError } from 'rxjs'; import { SernError } from '../structures/errors'; import { isNotFromBot } from '../utilities/messageHelpers'; import type { Module, ModuleDefs } from '../structures/module'; - -export function correctModuleType( - plug: Module | undefined, - type: T, -): plug is ModuleDefs[T] { - return plug !== undefined && plug.type === type; -} +import { correctModuleType } from '../utilities/predicates'; export function filterCorrectModule(cmdType: T) { return (src: Observable) => @@ -33,7 +27,7 @@ export function filterCorrectModule(cmdType: T) { 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/utilities/predicates.ts b/src/handler/utilities/predicates.ts new file mode 100644 index 0000000..cbcc326 --- /dev/null +++ b/src/handler/utilities/predicates.ts @@ -0,0 +1,8 @@ +import type { Module, ModuleDefs } from '../structures/module'; + +export function correctModuleType( + plug: Module | undefined, + type: T, +): plug is ModuleDefs[T] { + return plug !== undefined && plug.type === type; +} \ No newline at end of file diff --git a/src/handler/utilities/resolveParameters.ts b/src/handler/utilities/resolveParameters.ts deleted file mode 100644 index 33a2230..0000000 --- a/src/handler/utilities/resolveParameters.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type UnionToTuple = T extends readonly [infer V, infer S] - ? V extends V - ? S extends S - ? [V, S] - : [V] - : never - : never; diff --git a/src/types/handler.ts b/src/types/handler.ts index 05d79c6..bf94fbe 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -22,3 +22,11 @@ export type SlashOptions = Omit = Omit & T2; + +export type UnionToTuple = T extends readonly [infer V, infer S] + ? V extends V + ? S extends S + ? [V, S] + : [V] + : never + : never; \ No newline at end of file