From 4bdd8330d090a9f08eb52b2485165d038442a45f Mon Sep 17 00:00:00 2001 From: ITOH Date: Fri, 25 Mar 2022 00:04:23 +0100 Subject: [PATCH] feat(plugins): validate interaction response title (#2130) Modal titles must have a length between 1 and 45 characters. This adds a check to the permissions plugin. Reference: https://github.com/discord/discord-api-docs/pull/4649 --- plugins/permissions/src/interactions/mod.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/permissions/src/interactions/mod.ts b/plugins/permissions/src/interactions/mod.ts index afc56bde6..55a7738ef 100644 --- a/plugins/permissions/src/interactions/mod.ts +++ b/plugins/permissions/src/interactions/mod.ts @@ -6,6 +6,14 @@ export function sendInteractionResponse(bot: BotWithCache) { const sendInteractionResponseOld = bot.helpers.sendInteractionResponse; bot.helpers.sendInteractionResponse = function (id, token, options) { + if (options.data?.title !== undefined) { + if (!bot.utils.validateLength(options.data.title, { min: 1, max: 45 })) { + throw new Error( + "Invalid modal title. Must be between 1-45 characters long.", + ); + } + } + options.data?.choices?.every((choice) => { if (!bot.utils.validateLength(choice.name, { min: 1, max: 100 })) { throw new Error(