diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 65ec19f..e71e8f5 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -30,7 +30,7 @@ jobs: - name: Create Pull Request id: cpr - uses: peter-evans/create-pull-request@v4 + uses: peter-evans/create-pull-request@v5-beta with: commit-message: "chore: update JavaScript plugins" branch: js diff --git a/TypeScript/assertFields.ts b/TypeScript/assertFields.ts index 16b3518..67ebfe4 100644 --- a/TypeScript/assertFields.ts +++ b/TypeScript/assertFields.ts @@ -1,58 +1,58 @@ -//@ts-nocheck -/** - * This plugin checks the fields of a ModalSubmitInteraction - * with regex or a custom callback - * - * @author @jacoobes [<@182326315813306368>] - * @version 1.0.0 - * @example - * ```ts - * export default commandModule({ - * type: CommandType.Modal, - * plugins: [ - * assertFields({ - * fields: { - * // check the modal field "mcUsernameInput" with the regex /a+b+c/ - * mcUsernameInput: /a+b+c+/ - * }, - * failure: (errors, interaction) => { - * interaction.reply(errors.join("\n")) - * } - * }), - * ], - * execute: ctx => { - * ctx.reply("nice!") - * } - * }) - * ``` - */ -import { CommandControlPlugin, CommandType, controller } from "@sern/handler"; -import type { ModalSubmitInteraction } from "discord.js"; - -type Assertion = - | RegExp - | ((value : string) => boolean); - -export function assertFields(config: { - fields: Record, - failure: (errors: string[], interaction: ModalSubmitInteraction) => any -}) { - return CommandControlPlugin(modal => { - const pairs = Object.entries(config.fields); - const errors = []; - for(const [ field, assertion ] of pairs) { - // Keep in mind this doesn't check for typos! - // feel free to add more checks. - const input = modal.fields.getTextInputValue(field) - const resolvedAssertion = assertion instanceof RegExp ? (value: string) => assertion.test(value) : assertion; - if(!resolvedAssertion(input)) { - errors.push(input + " failed to pass assertion " + resolvedAssertion.toString() ) - } - } - if(errors.length > 0) { - config.failure(errors, modal); - return controller.stop(); - } - return controller.next(); - }) +//@ts-nocheck +/** + * This plugin checks the fields of a ModalSubmitInteraction + * with regex or a custom callback + * + * @author @jacoobes [<@182326315813306368>] + * @version 1.0.0 + * @example + * ```ts + * export default commandModule({ + * type: CommandType.Modal, + * plugins: [ + * assertFields({ + * fields: { + * // check the modal field "mcUsernameInput" with the regex /a+b+c/ + * mcUsernameInput: /a+b+c+/ + * }, + * failure: (errors, interaction) => { + * interaction.reply(errors.join("\n")) + * } + * }), + * ], + * execute: ctx => { + * ctx.reply("nice!") + * } + * }) + * ``` + */ +import { CommandControlPlugin, CommandType, controller } from "@sern/handler"; +import type { ModalSubmitInteraction } from "discord.js"; + +type Assertion = + | RegExp + | ((value : string) => boolean); + +export function assertFields(config: { + fields: Record, + failure: (errors: string[], interaction: ModalSubmitInteraction) => any +}) { + return CommandControlPlugin(modal => { + const pairs = Object.entries(config.fields); + const errors = []; + for(const [ field, assertion ] of pairs) { + // Keep in mind this doesn't check for typos! + // feel free to add more checks. + const input = modal.fields.getTextInputValue(field) + const resolvedAssertion = assertion instanceof RegExp ? (value: string) => assertion.test(value) : assertion; + if(!resolvedAssertion(input)) { + errors.push(input + " failed to pass assertion " + resolvedAssertion.toString() ) + } + } + if(errors.length > 0) { + config.failure(errors, modal); + return controller.stop(); + } + return controller.next(); + }) } \ No newline at end of file