feat : plugin api improvements, declarative ui

This commit is contained in:
Jacob Nguyen
2022-04-09 13:45:38 -05:00
parent 8866bff576
commit 136b0d23c5
2 changed files with 29 additions and 9 deletions

View File

@@ -13,7 +13,7 @@
//
import type { Err, Ok, Result } from "ts-results";
import type { Override } from "../..";
import type { Override, Wrapper } from "../..";
import type { BaseModule } from "../structures/modules/module";
export enum PluginType {
@@ -33,15 +33,15 @@ interface BasePlugin extends Override<BaseModule, executePlugin>{
type : PluginType
}
type CommandPlugin = {
export type CommandPlugin = {
type : PluginType.Command
} & BasePlugin;
} & Override<BasePlugin, { execute : ( wrapper : Wrapper ) => Result<void,void>}>;
type EventPlugin = {
export type EventPlugin = {
type : PluginType.Event
} & BasePlugin;
export type Plugin =
export type SernPlugin =
CommandPlugin
| EventPlugin;

View File

@@ -1,5 +1,6 @@
import type { Awaitable, ChatInputCommandInteraction, Interaction } from "discord.js";
import type { Args, Module } from "../../..";
import type { CommandPlugin, EventPlugin, SernPlugin } from "../../plugins/plugin";
import type Context from "../context";
export interface BaseModule {
@@ -8,8 +9,27 @@ export interface BaseModule {
execute: (ctx: Context, args: Args) => Awaitable<void>;
}
export function sernModule<T extends Module> (module : T, plugins : Plugin[]) {
export interface PluggedModule<T extends Module> {
mod : T;
plugins : SernPlugin[];
}
export function commmand ( plug : CommandPlugin ) {
return plug;
}
export function event( plug : EventPlugin ) {
return plug;
}
export function apply(...plugins: SernPlugin[]) {
return plugins;
}
export function sernModule<T extends Module>
(plugins : () => SernPlugin[], mod : T, ) : PluggedModule<T> {
return {
mod,
plugins : plugins()
}
}