diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index acf4b09..a7a5fad 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -5,7 +5,7 @@ import * as Files from '../utilities/readFile'; import { match } from 'ts-pattern'; import { SernError } from '../structures/errors'; import Context from '../structures/context'; -import { CommandType, controller } from '../sern'; +import { controller } from '../sern'; import type { Module } from '../structures/module'; import { isButton, @@ -15,6 +15,7 @@ import { isUserContextMenuCmd, } from '../utilities/predicates'; import { filterCorrectModule } from './observableHandling'; +import { CommandType } from '../structures/enums'; function applicationCommandHandler(mod: Module | undefined, interaction: CommandInteraction) { const mod$ = (cmdTy : T) => of(mod).pipe( diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index ce2d079..b094822 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -2,12 +2,13 @@ import type { Message } from 'discord.js'; import { concatMap, filter, from, fromEvent, map, Observable, of } from 'rxjs'; import { Err } from 'ts-results'; import type { Args } from '../..'; -import { CommandType, controller } from '../sern'; +import { controller } from '../sern'; import Context from '../structures/context'; import type Wrapper from '../structures/wrapper'; import { fmt } from '../utilities/messageHelpers'; import * as Files from '../utilities/readFile'; import { filterCorrectModule, ignoreNonBot } from './observableHandling'; +import { CommandType } from '../structures/enums'; export const onMessageCreate = (wrapper: Wrapper) => { const { client, defaultPrefix } = wrapper; diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 0f0c1b3..1ef8319 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -2,8 +2,7 @@ import { concat, concatMap, from, fromEvent, map, Observable, of, skip, take } f import { basename } from 'path'; import * as Files from '../utilities/readFile'; import type Wrapper from '../structures/wrapper'; -import { CommandType, controller } from '../sern'; -import type { PluginType } from '../plugins/plugin'; +import { controller } from '../sern'; import type { Result } from 'ts-results'; import type { Awaitable } from 'discord.js'; import type { Module } from '../structures/module'; @@ -12,6 +11,7 @@ import { ApplicationCommandType, ComponentType } from 'discord.js'; import { Err, Ok } from 'ts-results'; import { SernError } from '../structures/errors'; import type { DefinitelyDefined } from '../../types/handler'; +import { CommandType, PluginType } from '../structures/enums'; export const onReady = (wrapper: Wrapper) => { const { client, commands } = wrapper; diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index 3abaec4..19f6d22 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -13,9 +13,10 @@ import type { Awaitable, Client } from 'discord.js'; import type { Err, Ok, Result } from 'ts-results'; -import type { Module, Override, Wrapper } from '../..'; -import type { CommandType } from '../sern'; +import type { Module, Override } from '../..'; import type { BaseModule, ModuleDefs } from '../structures/module'; +import type { CommandType } from '../structures/enums'; +import { PluginType } from '../structures/enums'; export interface Controller { @@ -23,11 +24,6 @@ export interface Controller { stop: () => Err; } -export enum PluginType { - Command = 0b01, - Event = 0b10, -} - type executeCmdPlugin = (controller: Controller) => Result ; type BasePlugin = Override(...plug: (CommandPlugin | EventPl export function sernModule( plugs: (CommandPlugin | EventPlugin)[], mod : ModuleDefs[T] ) : ModuleDefs[T] { - //mod.plugins if defined, warn user to use first parameter - //mod.onEvent if defined, warn user to use first parameter const plugins = plugs.filter(el => el.type === PluginType.Command); const onEvent = plugs.filter(el => el.type === PluginType.Event); return { plugins, onEvent, ...mod - } as unknown as ModuleDefs[T]; + }; } diff --git a/src/handler/sern.ts b/src/handler/sern.ts index c143fe8..67e02fd 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -10,6 +10,7 @@ import { onMessageCreate } from './events/messageEvent'; import { onInteractionCreate } from './events/interactionCreate'; import { match, P } from 'ts-pattern'; import { Err, Ok } from 'ts-results'; +import { CommandType } from './structures/enums'; export function init(wrapper: Wrapper) { const { events, client } = wrapper; @@ -27,19 +28,6 @@ function eventObserver(client: Client, events: DiscordEvent[]) { }); } -/** - * @enum { number }; - */ -export enum CommandType { - Text = 0b0000001, - Slash = 0b0000010, - MenuUser = 0b0000100, - MenuMsg = 0b0001000, - Button = 0b0010000, - MenuSelect = 0b0100000, - Both = 0b0000011, -} - export function cmdTypeToDjs(ty: CommandType) { return match(ty) .with(CommandType.Slash, () => ApplicationCommandType.ChatInput) diff --git a/src/handler/structures/enums.ts b/src/handler/structures/enums.ts new file mode 100644 index 0000000..b0d2503 --- /dev/null +++ b/src/handler/structures/enums.ts @@ -0,0 +1,19 @@ +/** + * @enum { number }; + */ +enum CommandType { + Text = 0b0000001, + Slash = 0b0000010, + MenuUser = 0b0000100, + MenuMsg = 0b0001000, + Button = 0b0010000, + MenuSelect = 0b0100000, + Both = 0b0000011, +} + +enum PluginType { + Command = 0b01, + Event = 0b10, +} + +export { CommandType, PluginType }; \ No newline at end of file diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index 66e205b..cd208ee 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -8,10 +8,9 @@ import type { } from 'discord.js'; import type { Override } from '../../types/handler'; import type { Args } from '../../types/handler'; -import type { CommandType } from '../sern'; import type { CommandPlugin, EventPlugin } from '../plugins/plugin'; import type Context from './context'; -import type { PluginType } from '../plugins/plugin'; +import { CommandType, PluginType } from './enums'; export interface BaseModule { type : CommandType | PluginType @@ -47,7 +46,6 @@ export type ContextMenuUser = Override[]; plugins?: (CommandPlugin)[]; - description? : string; execute: (ctx: UserContextMenuCommandInteraction) => Awaitable }> @@ -55,7 +53,6 @@ export type ContextMenuMsg = Override[]; plugins?: CommandPlugin[]; - description? : string; execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable }>; diff --git a/src/handler/structures/structxports.ts b/src/handler/structures/structxports.ts index 5cc9686..dcf827c 100644 --- a/src/handler/structures/structxports.ts +++ b/src/handler/structures/structxports.ts @@ -1,5 +1,5 @@ import Context from './context'; import type { BothCommand, Module, SlashCommand, TextCommand } from './module'; import type Wrapper from './wrapper'; - +export * from './enums'; export { Context, SlashCommand, TextCommand, BothCommand, Module, Wrapper };