diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index e7b26cb..03669da 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -2,6 +2,7 @@ import type { Message } from "discord.js"; import { map, filter, fromEvent, Observable, of, concatMap, tap } from "rxjs"; import { None, Some } from "ts-results"; import { CommandType } from "../sern"; +import type { TextCommand } from "../structures/commands/module"; import Context from "../structures/context"; import type Wrapper from "../structures/wrapper"; import { isNotFromDM, isNotFromBot, hasPrefix, fmt } from "../utilities/messageHelpers"; @@ -25,7 +26,7 @@ export const onMessageCreate = (wrapper : Wrapper) => { ), filter( ([mod]) => mod !== undefined && (mod.type & CommandType.TEXT) != 0 ), tap ( ([ mod, ctx, args ]) => { - mod!.execute(ctx, ['text', args]) + (mod as TextCommand)!.execute(ctx, ['text', args]) }), ) ) diff --git a/src/handler/structures/commands/module.ts b/src/handler/structures/commands/module.ts index 7fdbc13..63f16ff 100644 --- a/src/handler/structures/commands/module.ts +++ b/src/handler/structures/commands/module.ts @@ -1,30 +1,34 @@ -import type { ApplicationCommandOptionData, Awaitable, Interaction } from "discord.js"; -import type { Args } from "../../../types/handler"; +import type { ApplicationCommandOptionData, Awaitable, ChatInputCommandInteraction, Interaction } from "discord.js"; +import type { Args, Override } from "../../../types/handler"; import type { CommandType } from "../../sern"; import type Context from "../context"; - +type executeSlash = { execute : (ctx : Context, args: Args) => Awaitable }; export interface BaseModule { name? : string; description : string; execute: (ctx: Context, args: Args) => Awaitable; } -export type Text = { +export type TextCommand = { type : CommandType.TEXT; alias : string[] | [], -}; -export type Slash = { +} & BaseModule; + +export type SlashCommand = { type : CommandType.SLASH; options : ApplicationCommandOptionData[] | [], -}; +} & Override; -export type Both = { +export type BothCommand = { type : CommandType.BOTH; alias : string[] | []; options : ApplicationCommandOptionData[] | [], -} +} & Override; + export type Module = - (BaseModule & Slash) | (BaseModule & Both) | (BaseModule & Text); - + TextCommand + | SlashCommand + | BothCommand; + diff --git a/src/handler/structures/commands/moduleHandler.ts b/src/handler/structures/commands/moduleHandler.ts index c30c239..0efa1b8 100644 --- a/src/handler/structures/commands/moduleHandler.ts +++ b/src/handler/structures/commands/moduleHandler.ts @@ -1,13 +1,13 @@ import { CommandType } from "../../sern"; -import type { Text, Both, Slash, BaseModule } from "./module"; +import type { TextCommand, BothCommand, SlashCommand, BaseModule } from "./module"; //https://stackoverflow.com/questions/64092736/alternative-to-switch-statement-for-typescript-discriminated-union // Explicit Module Definitions for mapping export type ModuleDefs = { - [CommandType.TEXT] : Text & BaseModule, - [CommandType.SLASH] : Slash & BaseModule, - [CommandType.BOTH] : Both & BaseModule, + [CommandType.TEXT] : TextCommand, + [CommandType.SLASH] : SlashCommand, + [CommandType.BOTH] : BothCommand, } //Keys of ModuleDefs diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts index c15e4e0..d7b0a2a 100644 --- a/src/handler/structures/context.ts +++ b/src/handler/structures/context.ts @@ -11,7 +11,7 @@ function firstSome(...args : Option[]) : T | null { return null; } -export default class Context { +export default class Context { private msg: Option = None; private interac: Option = None;