moving types to types/handler.ts

This commit is contained in:
jacoobes
2022-02-04 00:39:05 -06:00
parent 16b284b08e
commit 55ea90bdc0
2 changed files with 17 additions and 17 deletions

View File

@@ -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<Message>,
slash : Option<CommandInteraction>
}
export type ParseType = {
2 : string;
4 : Omit<CommandInteractionOptionResolver, "getMessage" | "getFocused">
6 : [string, Omit<CommandInteractionOptionResolver, "getMessage" | "getFocused">]
};
export interface Module<T> {
alias: string[],
@@ -137,7 +128,7 @@ export namespace Sern {
visibility : Visibility,
type: CommandType,
delegate : ( eventParams : Context , args: Ok<T> ) => Awaitable<Result<possibleOutput, string > | void>
parse? : (ctx: Context, parseable: ParseType[Module<T>["type"]] ) => Utils.ArgType<T>
parse? : <K extends keyof ParseType> (ctx: Context, cmdType : K, ...args: ParseType[K] ) => Utils.ArgType<T>
}

View File

@@ -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<unknown>["delegate"]
export enum CommandType {
TEXT = 2,
SLASH = 4,
}
}
export type Context = {
text : Option<Message>,
slash : Option<CommandInteraction>
}
export type ParseType = {
text : [arg: string];
slash : [options : Omit<CommandInteractionOptionResolver, "getMessage" | "getFocused">]
};