feat: add limit for attachment description (#2418)

* add limit for attachment description

* bot.transformers.reverse.attachment

* plugins/permissions: validate attachments
This commit is contained in:
LTS20050703
2022-09-03 12:35:41 -04:00
committed by GitHub
parent fec9d6e869
commit 3518ed1e18
13 changed files with 42 additions and 295 deletions
+9
View File
@@ -0,0 +1,9 @@
import { Attachment, Bot } from "../deps.ts";
export function validateAttachments(bot: Bot, attachments: Attachment[]) {
attachments.forEach((attachment) => {
if (attachment.description && !bot.utils.validateLength(attachment.description, { min: 0, max: 1024 })) {
throw new Error("Attachment description length must be less than 1024 characters");
}
});
}
@@ -7,6 +7,7 @@ import {
CONTEXT_MENU_COMMANDS_NAME_REGEX,
SLASH_COMMANDS_NAME_REGEX,
} from "../../deps.ts";
import { validateAttachments } from "../attachments.ts";
export function validateApplicationCommandOptions(
bot: BotWithCache,
@@ -176,6 +177,8 @@ export function editInteractionResponse(bot: BotWithCache) {
}
}
if (options.attachments) validateAttachments(bot, options.attachments);
return await editInteractionResponseOld(token, options);
};
}
@@ -1,4 +1,5 @@
import { AllowedMentionsTypes, BotWithCache } from "../../deps.ts";
import { validateAttachments } from "../attachments.ts";
export default function editFollowupMessage(bot: BotWithCache) {
const editFollowupMessageOld = bot.helpers.editFollowupMessage;
@@ -56,6 +57,8 @@ export default function editFollowupMessage(bot: BotWithCache) {
}
}
if (options.attachments) validateAttachments(bot, options.attachments);
return await editFollowupMessageOld(token, messageId, options);
};
}
@@ -1,4 +1,5 @@
import { AllowedMentionsTypes, BotWithCache, ChannelTypes, PermissionStrings } from "../../deps.ts";
import { validateAttachments } from "../attachments.ts";
import { validateComponents } from "../components.ts";
import { requireBotChannelPermissions } from "../permissions.ts";
@@ -165,6 +166,8 @@ export function editMessage(bot: BotWithCache) {
);
}
if (content.attachments) validateAttachments(bot, content.attachments);
return editMessageOld(channelId, messageId, content);
};
}
@@ -1,4 +1,5 @@
import { AllowedMentionsTypes, BotWithCache } from "../../deps.ts";
import { validateAttachments } from "../attachments.ts";
import { validateComponents } from "../components.ts";
export function editWebhookMessage(bot: BotWithCache) {
@@ -62,6 +63,8 @@ export function editWebhookMessage(bot: BotWithCache) {
if (options.components) validateComponents(bot, options.components);
if (options.attachments) validateAttachments(bot, options.attachments);
return await editWebhookMessageOld(webhookId, webhookToken, options);
};
}