From c8c0c841db2423e29d69bbc1a3ab590bfebb5d5b Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 17 May 2022 12:11:00 -0500 Subject: [PATCH] feat: Add DefinetlyDefined type, more todo statements --- src/handler/events/interactionCreate.ts | 4 +--- src/handler/events/messageEvent.ts | 3 ++- src/handler/events/readyEvent.ts | 7 ++++--- src/types/handler.ts | 4 +++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index f91f883..557ec7b 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -18,8 +18,6 @@ import { } from '../utilities/predicates'; import { filterCorrectModule } from './observableHandling'; -//TODO : atm, i have to cast for every interaction. is there a way to not cast? -// maybe pass it through an observable function applicationCommandHandler(mod: Module | undefined, interaction: CommandInteraction) { const mod$ = (cmdTy : T) => of(mod).pipe( filterCorrectModule(cmdTy) @@ -28,9 +26,9 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command return match(interaction) .when(isChatInputCommand, i => { const ctx = Context.wrap(i); + //SUPPORT COMMANDTYPE.BOTH return mod$(CommandType.Slash).pipe( concatMap(m => { - console.log(m); return of(m.onEvent.map(e => e.execute( [ctx, ['slash', i.options]], controller diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index 4671c90..6a0b476 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -31,7 +31,8 @@ export const onMessageCreate = (wrapper: Wrapper) => { const ensureModuleType$ = processMessage$.pipe( concatMap(payload => of(payload.mod).pipe( - filterCorrectModule(CommandType.Text), // fix for BothCommand + //SUPPORT COMMANDTYPE.BOTH + filterCorrectModule(CommandType.Text), map(mod => ({ ...payload, mod })), ), ), diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index fe8d6a3..61217c8 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -11,6 +11,7 @@ import { match } from 'ts-pattern'; import { ApplicationCommandType, ComponentType } from 'discord.js'; import { Err, Ok } from 'ts-results'; import { SernError } from '../structures/errors'; +import type { DefinetlyDefined, Override } from '../../types/handler'; export const onReady = (wrapper: Wrapper) => { const { client, commands } = wrapper; @@ -39,7 +40,7 @@ export const onReady = (wrapper: Wrapper) => { ( concat(ready$, processPlugins$) as Observable<{ - mod: Module; + mod: DefinetlyDefined; cmdPluginsRes: { execute: Awaitable>; type: PluginType.Command; @@ -69,8 +70,8 @@ export const onReady = (wrapper: Wrapper) => { }); }; -function registerModule(mod: Module) : Result { - const name = mod.name!; +function registerModule(mod: DefinetlyDefined) : Result { + const name = mod.name; return match(mod) .with({ type: CommandType.Text }, mod => { mod.alias.forEach(a => Files.TextCommands.aliases.set(a, mod)); diff --git a/src/types/handler.ts b/src/types/handler.ts index bf94fbe..487d590 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -29,4 +29,6 @@ export type UnionToTuple = T extends readonly [infer V, infer S] ? [V, S] : [V] : never - : never; \ No newline at end of file + : never; + +export type DefinetlyDefined = T & Override \ No newline at end of file