mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
plugin system loking better, tbd type
This commit is contained in:
@@ -24,7 +24,7 @@ export class DefaultErrorHandling implements ErrorHandling {
|
||||
* Version 4.0.0 will internalize this api. Please refrain from using ModuleStore!
|
||||
*/
|
||||
export class DefaultLogging implements Logging {
|
||||
private date = () => new Date();
|
||||
private date() { return new Date() }
|
||||
debug(payload: LogPayload): void {
|
||||
console.debug(`DEBUG: ${this.date().toISOString()} -> ${payload.message}`);
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ export function eventDispatcher(deps: Dependencies, module: Module, source: unkn
|
||||
`${source} cannot be constructed into an event listener`);
|
||||
const execute: OperatorFunction<unknown[]|undefined, unknown> =
|
||||
concatMap(async args => {
|
||||
if(args)
|
||||
return module.execute.apply(null, args);
|
||||
if(args) return module.execute.apply(null, args);
|
||||
});
|
||||
//@ts-ignore
|
||||
return fromEvent(source, module.name!)
|
||||
@@ -240,7 +239,7 @@ async function callPlugins({ args, module, deps }: ExecutePayload) {
|
||||
export function intoTask(onStop: (m: Module) => unknown) {
|
||||
const onNext = ({ args, module, deps }: ExecutePayload, state: Record<string, unknown>) => ({
|
||||
module,
|
||||
args: [...args, { state }],
|
||||
args: [...args, { state, deps }],
|
||||
deps
|
||||
});
|
||||
return createResultResolver({ onStop, onNext })
|
||||
|
||||
@@ -20,13 +20,13 @@ function hasPrefix(prefix: string, content: string) {
|
||||
return (prefixInContent.localeCompare(prefix, undefined, { sensitivity: 'accent' }) === 0);
|
||||
}
|
||||
|
||||
export default function message(
|
||||
export default function (
|
||||
deps: UnpackedDependencies,
|
||||
defaultPrefix: string | undefined
|
||||
defaultPrefix?: string
|
||||
) {
|
||||
const {"@sern/emitter": emitter,
|
||||
'@sern/logger': log,
|
||||
'@sern/client': client } = deps
|
||||
'@sern/client': client} = deps
|
||||
|
||||
if (!defaultPrefix) {
|
||||
log?.debug({ message: 'No prefix found. message handler shutting down' });
|
||||
|
||||
@@ -21,7 +21,8 @@ import { AnyCommandPlugin, AnyEventPlugin, ControlPlugin, InitPlugin } from './c
|
||||
import { Awaitable, SernEventsMapping } from './utility';
|
||||
|
||||
type ToBeDecided = {
|
||||
result: Record<string,unknown>;
|
||||
state: Record<string,unknown>;
|
||||
deps: Dependencies
|
||||
}
|
||||
export type Processed<T> = T & { name: string; description: string };
|
||||
|
||||
@@ -62,12 +63,12 @@ export interface CronEventCommand extends Module {
|
||||
|
||||
export interface ContextMenuUser extends Module {
|
||||
type: CommandType.CtxUser;
|
||||
execute: (ctx: UserContextMenuCommandInteraction) => Awaitable<unknown>;
|
||||
execute: (ctx: UserContextMenuCommandInteraction, tbd: ToBeDecided) => Awaitable<unknown>;
|
||||
}
|
||||
|
||||
export interface ContextMenuMsg extends Module {
|
||||
type: CommandType.CtxMsg;
|
||||
execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable<unknown>;
|
||||
execute: (ctx: MessageContextMenuCommandInteraction, tbd: ToBeDecided) => Awaitable<unknown>;
|
||||
}
|
||||
|
||||
export interface ButtonCommand extends Module {
|
||||
@@ -118,21 +119,21 @@ export interface DiscordEventCommand<T extends keyof ClientEvents = keyof Client
|
||||
}
|
||||
export interface TextCommand extends Module {
|
||||
type: CommandType.Text;
|
||||
execute: (ctx: Context) => Awaitable<unknown>;
|
||||
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
|
||||
}
|
||||
|
||||
export interface SlashCommand extends Module {
|
||||
type: CommandType.Slash;
|
||||
description: string;
|
||||
options?: SernOptionsData[];
|
||||
execute: (ctx: Context) => Awaitable<unknown>;
|
||||
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
|
||||
}
|
||||
|
||||
export interface BothCommand extends Module {
|
||||
type: CommandType.Both;
|
||||
description: string;
|
||||
options?: SernOptionsData[];
|
||||
execute: (ctx: Context) => Awaitable<unknown>;
|
||||
execute: (ctx: Context, tbd: ToBeDecided) => Awaitable<unknown>;
|
||||
}
|
||||
|
||||
export type EventModule = DiscordEventCommand | SernEventCommand | ExternalEventCommand | CronEventCommand;
|
||||
|
||||
Reference in New Issue
Block a user