From b04845e4936a5de12c97d53a6d0c4f9b3693f0ca Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:35:05 -0600 Subject: [PATCH 1/2] feat: fromCallback.ts --- plugins/fromCallback.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 plugins/fromCallback.ts diff --git a/plugins/fromCallback.ts b/plugins/fromCallback.ts new file mode 100644 index 0000000..b1e049f --- /dev/null +++ b/plugins/fromCallback.ts @@ -0,0 +1,37 @@ +//@ts-nocheck +/** + * @plugin + * fromCallback turns a callback into a plugin result. + * if the callback returns truthy value, plugin continues. + * This control plugin works for every command type. The arguments of the callback + * mirror the execute method on the current module. + * @author @jacoobes [<@182326315813306368>] + * @version 1.0.0 + * @example + * ```ts + * const myServer = "941002690211766332"; + * export default commandModule({ + * type: CommandType.Both, + * plugins: [ + * //This plugin prevents this command module from executing in other servers except myServer + * fromCallback((ctx, args) => ctx.guildId == myServer) + * ], + * execute: ctx => { + * ctx.reply("I only respond in myServer!"); + * } + * }) + * ``` + * @end + */ + + +import { PluginType, makePlugin, controller } from "@sern/handler"; + +export const fromCallback = (cb: (...args: any[]) => boolean) => + makePlugin(PluginType.Control, (...args) => { + console.log(args) + if(cb.apply(null, args)) { + return controller.next(); + } + return controller.stop(); + }); From c4e4f09d1bc7a53b613903ee80207d9bd6373f56 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 2 Jan 2024 13:52:37 -0600 Subject: [PATCH 2/2] Update fromCallback.ts oops forgot to un-console log --- plugins/fromCallback.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/fromCallback.ts b/plugins/fromCallback.ts index b1e049f..87e2b03 100644 --- a/plugins/fromCallback.ts +++ b/plugins/fromCallback.ts @@ -29,7 +29,7 @@ import { PluginType, makePlugin, controller } from "@sern/handler"; export const fromCallback = (cb: (...args: any[]) => boolean) => makePlugin(PluginType.Control, (...args) => { - console.log(args) + //console.log(args) if(cb.apply(null, args)) { return controller.next(); }