diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index bc1421b..c8bfb46 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -12,7 +12,7 @@ import { match } from 'ts-pattern'; import { SernError } from '../structures/errors'; import Context from '../structures/context'; import { controller } from '../sern'; -import type { AutocompleteCommand, Module, SlashCommand } from '../structures/module'; +import type { Module } from '../structures/module'; import { isButton, isChatInputCommand, diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index d21a0e4..3b7892b 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -21,7 +21,7 @@ export const onMessageCreate = (wrapper: Wrapper) => { map(message => { const [prefix, ...rest] = fmt(message, defaultPrefix); return { - ctx: Context.wrap(message), //TODO : check for BothCommand + ctx: Context.wrap(message), args: ['text', rest], mod: Files.TextCommands.text.get(prefix) ?? diff --git a/src/handler/events/observableHandling.ts b/src/handler/events/observableHandling.ts index 9449f49..a5ce95c 100644 --- a/src/handler/events/observableHandling.ts +++ b/src/handler/events/observableHandling.ts @@ -1,9 +1,13 @@ -import type { Message } from 'discord.js'; +import type { Awaitable, Message } from 'discord.js'; import { Observable, throwError } from 'rxjs'; import { SernError } from '../structures/errors'; import type { InteractionDefs, Module, ModuleDefs } from '../structures/module'; import { correctModuleType } from '../utilities/predicates'; import type { CommandType } from '../structures/enums'; +import type { UnionToIntersection } from '../../types/handler'; +import { controller } from '../sern'; +import type { Result } from 'ts-results'; +import type { SelectMenuInteraction } from 'discord.js'; export function filterCorrectModule(cmdType: T) { return (src: Observable) => @@ -45,13 +49,20 @@ export function ignoreNonBot(prefix: string) { }); } -export function processOnEvents(interaction: InteractionDefs[T]) { - return (src: Observable) => - new Observable(subscriber => { - return src.subscribe({ - next(m) {}, - error: e => subscriber.error(e), - complete: () => subscriber.complete(), - }); - }); -} +// export function processOnEvents(ty: T, interaction: InteractionDefs[T]) { +// return (src: Observable) => +// new Observable>>(subscriber => { +// return src.subscribe({ +// next(m) { +// subscriber.next(m.onEvent?.map(e => { +// return (>e).execute( +// [interaction as SelectMenuInteraction], //This is just to satisfy compiler +// controller, +// ); +// })) ; +// }, +// error: e => subscriber.error(e), +// complete: () => subscriber.complete(), +// }); +// }); +// } diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index 342a7ba..ca8227d 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -45,16 +45,29 @@ export type CommandPlugin = Override< //TODO: rn adding the modType check a little hackish. Find better way to determine the // module type of the event plugin -export type EventPlugin = Override< - BasePlugin, - { - type: PluginType.Event; - execute: ( - event: Parameters, - controller: Controller, - ) => Awaitable>; - } ->; +// export type EventPlugin = Override< +// BasePlugin, +// { +// type: PluginType.Event; +// execute: ( +// event: Parameters, +// controller: Controller, +// ) => Awaitable>; +// } +// >; + +export type EventPlugin = { + [K in T]: Override< + BasePlugin, + { + type: PluginType.Event; + execute: ( + event: Parameters, + controller: Controller, + ) => Awaitable>; + } + >; +}[T]; export function plugins(...plug: CommandPlugin[]): CommandPlugin[]; export function plugins(...plug: EventPlugin[]): EventPlugin[]; diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index d6b862d..42b51d5 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -21,7 +21,7 @@ import type Context from './context'; import { CommandType, PluginType } from './enums'; import type { AutocompleteInteraction } from 'discord.js'; import type { ApplicationCommandOptionType } from 'discord.js'; -import { ChatInputCommandInteraction, Message } from 'discord.js'; +import { ChatInputCommandInteraction, Message, User } from 'discord.js'; export interface BaseModule { type: CommandType | PluginType; @@ -119,8 +119,8 @@ export type ModalSubmitCommand = Override< export type AutocompleteCommand = Override< BaseModule, { - name: string; type: CommandType.Autocomplete; + name: string; onEvent?: EventPlugin[]; execute: (ctx: AutocompleteInteraction) => Awaitable; } @@ -150,7 +150,6 @@ export type ModuleDefs = { [CommandType.Modal]: ModalSubmitCommand; [CommandType.Autocomplete]: AutocompleteCommand; }; - export type InteractionDefs = { [CommandType.Text]: Context; [CommandType.Slash]: Context; diff --git a/src/index.ts b/src/index.ts index 4fd70b9..76c383b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,8 @@ +import type { UnionToIntersection } from './types/handler'; +import type { Module } from './handler/structures/module'; + export * as Sern from './handler/sern'; export * from './types/handler'; export * from './handler/structures/structxports'; export * from './handler/plugins/plugin'; +let p: UnionToIntersection; diff --git a/src/types/handler.ts b/src/types/handler.ts index fb42a53..e14f8f0 100644 --- a/src/types/handler.ts +++ b/src/types/handler.ts @@ -23,10 +23,15 @@ export type SlashOptions = Omit = Omit & T2; export type DefinitelyDefined = T & Override; -export type Expand = T extends object ? { [K in keyof T]: Expand } : T; type Reconstruct = T extends Omit ? O & Reconstruct : T; type IsOptional = { [K in keyof T]-?: T[K] extends Required[K] ? false : true; }; + +export type UnionToIntersection = (T extends unknown ? (x: T) => unknown : never) extends ( + x: infer R, +) => unknown + ? R + : never;