// // Plugins can be inserted on all commands and are emitted // // 1.) on ready event, where all commands are loaded. // 2.) on corresponding observable (command triggers) // // The goal of plugins is to organize commands and // provide extensions to repetitive patterns // examples include refreshing modules, // categorizing commands, cooldowns, permissions, etc. // Plugins are reminiscent of middleware in express. // 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 { BaseModule, ModuleDefs } from '../structures/module'; export interface Controller { next: () => Ok; stop: () => Err; } export enum PluginType { Command = 0b01, Event = 0b10, } type executeCmdPlugin = { execute: (wrapper: Wrapper, controller: Controller) => Result }; interface BasePlugin extends Override { type: PluginType; } export type CommandPlugin = { type: PluginType.Command; } & Override Awaitable>; }>; //TODO: rn adding the modType check a little hackish. Find better way to determine the // module type of the event plugin export type EventPlugin = { type: PluginType.Event; modType: T; } & Override, controller: Controller) => Awaitable>; }>; export function plugins(...plug: CommandPlugin[]): CommandPlugin[]; export function plugins(...plug: EventPlugin[]): EventPlugin[]; export function plugins(...plug: CommandPlugin[] | EventPlugin[]) { return plug; } export function sernModule(mod: Module): Module { return mod; }