mirror of
https://github.com/sern-handler/handler
synced 2026-06-15 04:12:17 +00:00
feat : plugin api improvements, declarative ui
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user