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
This commit is contained in:
ITOH
2022-03-25 00:04:23 +01:00
committed by GitHub
parent a575324c9d
commit 4bdd8330d0
@@ -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(