Skip to content

Commit

Permalink
feat: better looking typings for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed May 17, 2022
1 parent 2b81d53 commit 53bc080
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/handler/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import * as Files from '../utilities/readFile';
import { match } from 'ts-pattern';
import { SernError } from '../structures/errors';
import Context from '../structures/context';
import type { Result } from 'ts-results';
import { CommandType, controller } from '../sern';
import type { Module, ModuleDefs} from '../structures/module';
import type { EventPlugin } from '../plugins/plugin';
import type { Module } from '../structures/module';
import {
isButton,
isChatInputCommand,
Expand Down
36 changes: 22 additions & 14 deletions src/handler/structures/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,67 @@ import type { Args } from '../../types/handler';
import type { CommandType } from '../sern';
import type { CommandPlugin, EventPlugin } from '../plugins/plugin';
import type Context from './context';
import { Base } from 'discord.js';
import type { PluginType } from '../plugins/plugin';

export interface BaseModule {
type : CommandType | PluginType
name?: string;
description: string;
execute: (ctx: Context, args: Args) => Awaitable<void>;
}

//possible refactoring types into interfaces and not types
export type TextCommand = {
export type TextCommand = Override<BaseModule, {
type: CommandType.Text;
onEvent?: EventPlugin<CommandType.Text>[]
plugins?: CommandPlugin[];
alias?: string[];
} & BaseModule;
}>;

export type SlashCommand = {
export type SlashCommand = Override<BaseModule, {
type: CommandType.Slash;
onEvent?: EventPlugin<CommandType.Slash>[]
plugins?: (CommandPlugin)[];
options: ApplicationCommandOptionData[] | [];
} & BaseModule;

export type BothCommand = {
}>;

export type BothCommand = Override<BaseModule, {
type: CommandType.Both;
onEvent?: EventPlugin<CommandType.Both>[]
plugins?: (CommandPlugin)[]
alias?: string[];
options: ApplicationCommandOptionData[] | [];
} & BaseModule;
}>;

export type ContextMenuUser = {
export type ContextMenuUser = Override<BaseModule, {
type: CommandType.MenuUser;
onEvent?: EventPlugin<CommandType.MenuUser>[];
plugins?: (CommandPlugin)[];
} & Override<BaseModule, { execute: (ctx: UserContextMenuCommandInteraction) => Awaitable<void> }>;
execute: (ctx: UserContextMenuCommandInteraction) => Awaitable<void>
}>

export type ContextMenuMsg = {
export type ContextMenuMsg = Override<BaseModule, {
type: CommandType.MenuMsg;
onEvent?: EventPlugin<CommandType.MenuMsg>[];
plugins?: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable<void> }>;
execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable<void>
}>;

export type ButtonCommand = {
export type ButtonCommand = Override<BaseModule,{
type: CommandType.Button;
onEvent?: EventPlugin<CommandType.Button>[];
plugins?: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: ButtonInteraction) => Awaitable<void> }>;
execute: (ctx: ButtonInteraction) => Awaitable<void>
}>;

export type SelectMenuCommand = {
export type SelectMenuCommand = Override<BaseModule, {
type: CommandType.MenuSelect;
onEvent?: EventPlugin<CommandType.MenuSelect>[];
plugins?: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: SelectMenuInteraction) => Awaitable<void> }>;
execute: (ctx: SelectMenuInteraction) => Awaitable<void>
}>;

export type Module =
| TextCommand
Expand Down

0 comments on commit 53bc080

Please sign in to comment.