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 1/3] 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; +} From df745ca85e4188b4cac867ad3357b989d97ba40c Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:51:56 -0500 Subject: [PATCH 2/3] Update filterA.ts --- plugins/filterA.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/filterA.ts b/plugins/filterA.ts index 2b4d78d..743e49f 100644 --- a/plugins/filterA.ts +++ b/plugins/filterA.ts @@ -2,10 +2,10 @@ import { PluginType, makePlugin, controller, ControlPlugin } from "@sern/handler import type { AutocompleteInteraction } from 'discord.js' /** + * @plugin * @author jacoobes * @version 1.0.0 * @description filters autocomplete interaction that pass the criteria - * @license null * @example * ```ts * import { CommandType, commandModule } from "@sern/handler"; @@ -27,6 +27,7 @@ import type { AutocompleteInteraction } from 'discord.js' * ], * execute: (ctx, args) => {} * }) + * @end */ export const filterA = (pred: (value: string) => boolean) => { return makePlugin(PluginType.Control, (a: AutocompleteInteraction) => { From fa3da55b113d37fc825c1f6c8634d66acdb30812 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 9 Sep 2023 00:56:32 -0500 Subject: [PATCH 3/3] Update filterA.ts --- plugins/filterA.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/filterA.ts b/plugins/filterA.ts index 743e49f..0adc6f8 100644 --- a/plugins/filterA.ts +++ b/plugins/filterA.ts @@ -2,10 +2,10 @@ import { PluginType, makePlugin, controller, ControlPlugin } from "@sern/handler import type { AutocompleteInteraction } from 'discord.js' /** - * @plugin - * @author jacoobes + * @plugin + * filters autocomplete interaction that pass the criteria + * @author jacoobes [<@182326315813306368>] * @version 1.0.0 - * @description filters autocomplete interaction that pass the criteria * @example * ```ts * import { CommandType, commandModule } from "@sern/handler";