From 5b0e85f55c2edee586c41281daa4f994aad59685 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:51:14 -0500 Subject: [PATCH] Create filterA.ts --- plugins/filterA.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/filterA.ts diff --git a/plugins/filterA.ts b/plugins/filterA.ts new file mode 100644 index 0000000..2b4d78d --- /dev/null +++ b/plugins/filterA.ts @@ -0,0 +1,38 @@ +import { PluginType, makePlugin, controller, ControlPlugin } from "@sern/handler"; +import type { AutocompleteInteraction } from 'discord.js' + +/** + * @author jacoobes + * @version 1.0.0 + * @description filters autocomplete interaction that pass the criteria + * @license null + * @example + * ```ts + * import { CommandType, commandModule } from "@sern/handler"; + * import { filterA } from '../plugins/filterA.js' + * export default commandModule({ + * type : CommandType.Slash, + * options: [ + * { + * autocomplete: true, + * command : { + * //only accept autocomplete interactions that include 'poo' in the text + * onEvent: [filterA(s => s.includes('poo'))], + * execute: (autocomplete) => { + * let data = [{ name: 'pooba', value: 'first' }, { name: 'pooga', value: 'second' }] + * autocomplete.respond(data) + * } + * } + * } + * ], + * execute: (ctx, args) => {} + * }) + */ +export const filterA = (pred: (value: string) => boolean) => { + return makePlugin(PluginType.Control, (a: AutocompleteInteraction) => { + if(pred(a.options.getFocused())) { + return controller.next(); + } + return controller.stop(); + }) as ControlPlugin; +}