mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
* feat: experimental plugin changes * more refactors and name changes * feat: update name usage and update dispatchers.ts * fix:naming * feat: slightly safer typings than any[] * fix: forgot to destructure arguments * feat: add special function * fix: typings * feat: SUPER SIMPLIFY!!! * refactor: move promisifiedPlugins closer to call site * refactor: typings * refactor: typings * refactor: consolidate resolving initplugins into one function * refactor: better types * revert: remove unneeded function * revert: remove unneeded function * feat: dispatch work, simplify * feat: move some observableHandling function to operators for clarity * feat: simplify and document * feat: simplifying sern and docs * fix: typings * docs: clarity of function name * docs: add documentation for executeModule * feat: contextArgs overloads * docs: found out why * fix: typings * feat: shorten operators signature * refactor: switch to correct convention * refactor: take(1) -> first() * refactor: revert * refactor: safer typings (less any) and more accurate typings * style: prettier and short type aliases * fix: typings * fix: typings * docs: add deprecations * refactor: organization and moving stuff * pretty: prettey * docs: describe file * chore: update dependencies and version * docs: fix link for docasaurus * refactor: using a more appropriate operator function for closing an observable on crash * fix!: changing single and many * refactor: typings and simplifying composeRoot * fix: re-add logger into handleError * docs: comment * docs: new section * feat: help mitigate breaking changes * feat: help mitigate breaking changes * feat: help mitigate breaking changes and function overloads * feat: deprecate instead of remove * feat: partial remove and deprecate old symbols * revert: trying to accommodate old plugins is too difficult * docs: add many as deprecated * docs: update * feat: partial backwards compatability * refactor: renaming, docs, and exports more clean * refactor: context got a lot simpler * refactor: imports * docs: explain methods
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
/*
|
|
* Plugins can be inserted on all commands and are emitted
|
|
*
|
|
* 1. On ready event, where all commands are loaded.
|
|
* 2. On corresponding observable (when command triggers)
|
|
*
|
|
* The goal of plugins is to organize commands and
|
|
* provide extensions to repetitive patterns
|
|
* examples include refreshing modules,
|
|
* categorizing commands, cool-downs, permissions, etc.
|
|
* Plugins are reminiscent of middleware in express.
|
|
*/
|
|
|
|
import type { Awaitable } from 'discord.js';
|
|
import type { Err, Ok, Result } from 'ts-results-es';
|
|
import type { PluginType } from '../handler/structures/enums';
|
|
import type { CommandModule, EventModule } from './module';
|
|
import type { CommandArgs, InitArgs } from '../handler/plugins';
|
|
import type { Deprecated, Processed } from './handler';
|
|
import type { CommandType } from '../handler/structures/enums';
|
|
export type PluginResult = Awaitable<VoidResult>;
|
|
export type VoidResult = Result<void, void>;
|
|
|
|
export interface Controller {
|
|
next: () => Ok<void>
|
|
stop: () => Err<void>
|
|
}
|
|
export interface Plugin<Args extends any[] = any[]> {
|
|
type: PluginType;
|
|
execute: (...args: Args) => PluginResult;
|
|
}
|
|
|
|
export interface InitPlugin<Args extends any[] = any[]> {
|
|
type: PluginType.Init;
|
|
execute: (...args: Args) => PluginResult;
|
|
}
|
|
export interface ControlPlugin<Args extends any[] = any[]> {
|
|
type: PluginType.Control;
|
|
execute: (...args: Args) => PluginResult;
|
|
}
|
|
|
|
export type AnyCommandPlugin = ControlPlugin | InitPlugin<[InitArgs<Processed<CommandModule>>]>;
|
|
export type AnyEventPlugin = ControlPlugin | InitPlugin<[InitArgs<Processed<EventModule>>]>;
|
|
|
|
/**
|
|
* @deprecated
|
|
* Use the newer helper functions and import { controller } from '@sern/handler'
|
|
*/
|
|
export interface CommandPlugin<T extends CommandType = CommandType> {
|
|
name?: string;
|
|
description?: string;
|
|
type: PluginType.Command;
|
|
execute: (m: InitArgs<Processed<CommandModule>>, controller?: Deprecated<'Please import controller instead'>) => PluginResult;
|
|
}
|
|
/**
|
|
* @deprecated
|
|
* Use the newer helper functions
|
|
*/
|
|
export interface EventPlugin<T extends CommandType> {
|
|
name?: string;
|
|
description?: string;
|
|
type: PluginType.Event;
|
|
execute: (args : CommandArgs<T, PluginType.Event>, controller?: Controller) => PluginResult
|
|
}
|
|
export type DiscordEmitterPlugin = Deprecated<'Please view alternatives: '>;
|
|
export type ExternalEmitterPlugin = Deprecated<'Please view alternatives: '>;
|
|
export type SernEmitterPlugin = Deprecated<'Please view alternatives: '>;
|
|
export type AutocompletePlugin = Deprecated<'Please view alternatives: '>;
|
|
export type SernEventPlugin = Deprecated<'Please view alternatives: '>;
|
|
export type ExternalEventPlugin = Deprecated<'Please view alternatives: '>;
|
|
export type DiscordEventPlugin = Deprecated<'Please view alternatives: '>;
|