diff --git a/src/handler/sern/sern.ts b/src/handler/sern/sern.ts index 8165d2f..b4fcba9 100644 --- a/src/handler/sern/sern.ts +++ b/src/handler/sern/sern.ts @@ -1,4 +1,4 @@ -import type { MessagePackage, Nullable, Visibility } from "../../types/handler/handler"; +import type { Context, MessagePackage, Nullable, ParseType, Visibility } from "../../types/handler/handler"; import { CommandType } from "../../types/handler/handler"; import { Files } from "../utils/readFile" import type { ApplicationCommandOptionData, Awaitable, Client, CommandInteraction, CommandInteractionOptionResolver, Message} from "discord.js"; @@ -65,8 +65,8 @@ export namespace Sern { }); if(module.mod.type < CommandType.SLASH) return "This is not a slash command"; - const context = {text: None, slash: Some(interaction)} - const parsedArgs = module.mod.parse?.(context, interaction.options) ?? Ok(""); + const context = {text: None, slash: Some(interaction)} + const parsedArgs = module.mod.parse?.(context, "slash", interaction.options) ?? Ok(""); if(parsedArgs.err) return parsedArgs.val; const fn = await module.mod.delegate(context, parsedArgs); return fn?.val; @@ -79,7 +79,7 @@ export namespace Sern { } if (module.type === CommandType.SLASH) return `This may be a slash command and not a legacy command` const context = {text: Some(message), slash: None} - const parsedArgs = module.parse?.(context, args) ?? Ok(""); + const parsedArgs = module.parse?.(context, "text", args) ?? Ok(""); if(parsedArgs.err) return parsedArgs.val; let fn = await module.delegate(context, parsedArgs) return fn?.val @@ -120,16 +120,7 @@ export namespace Sern { readonly privateServerId : string } - export type Context = { - text : Option, - slash : Option - } - export type ParseType = { - 2 : string; - 4 : Omit - 6 : [string, Omit] - }; - + export interface Module { alias: string[], @@ -137,7 +128,7 @@ export namespace Sern { visibility : Visibility, type: CommandType, delegate : ( eventParams : Context , args: Ok ) => Awaitable | void> - parse? : (ctx: Context, parseable: ParseType[Module["type"]] ) => Utils.ArgType + parse? : (ctx: Context, cmdType : K, ...args: ParseType[K] ) => Utils.ArgType } diff --git a/src/types/handler/handler.ts b/src/types/handler/handler.ts index f591372..4c0c2d0 100644 --- a/src/types/handler/handler.ts +++ b/src/types/handler/handler.ts @@ -1,5 +1,5 @@ import type { Ok, Result, Option } from 'ts-results'; -import type { Awaitable, Client, CommandInteraction, Message, MessagePayload} from 'discord.js'; +import type { Awaitable, Client, CommandInteraction, CommandInteractionOptionResolver, Message, MessagePayload} from 'discord.js'; import type { MessageOptions } from 'child_process'; import type { Sern } from '../../handler/sern/sern'; @@ -18,4 +18,13 @@ export type delegate = Sern.Module["delegate"] export enum CommandType { TEXT = 2, SLASH = 4, -} \ No newline at end of file +} + +export type Context = { + text : Option, + slash : Option +} +export type ParseType = { + text : [arg: string]; + slash : [options : Omit] +};