From 4cdbf1983d77652965ea36871a6fd24a546d4f18 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Tue, 14 Mar 2023 09:24:48 +1100 Subject: [PATCH] Use RegExp for special character matching. --- src/events/messageCreate.ts | 3 ++- src/events/messageUpdate.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 3f93fe5..a695bad 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -3,7 +3,8 @@ import TClient from '../client'; export default { async run(client:TClient, message:Discord.Message){ if (message.author.bot || message.channel.type === ChannelType.DM) return; - const msgarr = message.content.toLowerCase().replaceAll('\n', ' ').split(' '); + //const msgarr = message.content.toLowerCase().replaceAll('\n', ' ').split(' '); + const msgarr = message.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' '); let automodded: boolean; const Whitelist = [] // Array of channel ids for automod to be disabled in (Disables bannedWords and advertisement, mind you.) diff --git a/src/events/messageUpdate.ts b/src/events/messageUpdate.ts index fc5be9a..631c05d 100644 --- a/src/events/messageUpdate.ts +++ b/src/events/messageUpdate.ts @@ -5,7 +5,7 @@ export default { if (!client.config.botSwitches.logs) return; const disabledChannels = ['548032776830582794', '541677709487505408'] if (oldMsg.guild?.id != client.config.mainServer.id || oldMsg.author == null || oldMsg?.author.bot || oldMsg.partial || newMsg.partial || !newMsg.member || disabledChannels.includes(newMsg.channelId)) return; - const msgarr = newMsg.content.toLowerCase().replaceAll('\n', ' ').split(' '); + const msgarr = newMsg.content.toLowerCase().replaceAll(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?\n]/g, ' ').split(' '); if (await client.bannedWords._content.findOne({_id:msgarr}) && (!client.isStaff(newMsg.member))) newMsg.delete(); if (newMsg.content === oldMsg.content) return; (client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColor).setTimestamp().setAuthor({name: `Author: ${oldMsg.author.tag} (${oldMsg.author.id})`, iconURL: `${oldMsg.author.displayAvatarURL()}`}).setTitle('Message edited').setDescription(`<@${oldMsg.author.id}>\nOld content:\n\`\`\`\n${oldMsg.content.length < 1 ? '(Attachment)' : oldMsg.content}\n\`\`\`\nNew content:\n\`\`\`\n${newMsg.content}\`\`\`\nChannel: <#${oldMsg.channelId}>`)], components: [new ActionRowBuilder().addComponents(new ButtonBuilder().setStyle(5).setURL(`${oldMsg.url}`).setLabel('Jump to message'))]});