From a5c40a58bf81f81dc2a280b2c542f5a339e21016 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 15 Sep 2020 01:02:28 +0300 Subject: [PATCH] automod: make match_attachment_type case-insensitive --- .../Automod/triggers/matchAttachmentType.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts index 37bb2053..308e0c8b 100644 --- a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts +++ b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts @@ -37,9 +37,16 @@ export const MatchAttachmentTypeTrigger = automodTrigger()({ const attachments: any[] = context.message.data.attachments; for (const attachment of attachments) { - const attachmentType = attachment.filename.split(`.`).pop(); + const attachmentType = attachment.filename + .split(".") + .pop() + .toLowerCase(); - if (trigger.blacklist_enabled && trigger.filetype_blacklist.includes(attachmentType)) { + const blacklist = trigger.blacklist_enabled + ? (trigger.filetype_blacklist || []).map(_t => _t.toLowerCase()) + : null; + + if (blacklist && blacklist.includes(attachmentType)) { return { extra: { matchedType: attachmentType, @@ -48,7 +55,11 @@ export const MatchAttachmentTypeTrigger = automodTrigger()({ }; } - if (trigger.whitelist_enabled && !trigger.filetype_whitelist.includes(attachmentType)) { + const whitelist = trigger.whitelist_enabled + ? (trigger.filetype_whitelist || []).map(_t => _t.toLowerCase()) + : null; + + if (whitelist && !whitelist.includes(attachmentType)) { return { extra: { matchedType: attachmentType,