From 86ae34743f04168716616f8a5deb1658010951b1 Mon Sep 17 00:00:00 2001 From: Jesse Jafa Date: Sat, 15 Oct 2022 16:39:09 +0300 Subject: [PATCH 1/2] fix: @everyone/@here mentions --- app/discord/automod.ts | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/app/discord/automod.ts b/app/discord/automod.ts index 2306473..e8c790a 100644 --- a/app/discord/automod.ts +++ b/app/discord/automod.ts @@ -16,22 +16,13 @@ const spamKeywords = [ "deepfake", "poki", ].map((x) => new RegExp(x)); -const spamPings = ["@everyone", "@here"]; + const safeKeywords = ["forhire", "hiring", "remote", "onsite"]; const checkWords = (message: string, wordList: string[]) => message.split(/\b/).some((word) => wordList.includes(word.toLowerCase())); -const getPingCount = (content: string) => { - return spamPings.reduce( - (sum, pingKeyword) => (content.includes(pingKeyword) ? sum + 1 : sum), - 0, - ); -}; - -export const isSpam = (content: string, threshold = 4) => { - const pingCount = getPingCount(content); - +const isSpam = (content: string, threshold = 4) => { const numberOfSpamKeywords = spamKeywords.reduce( (accum, spamTrigger) => (spamTrigger.test(content) ? accum + 1 : accum), 0, @@ -44,8 +35,6 @@ export const isSpam = (content: string, threshold = 4) => { const score = Number(hasLink) * 2 + numberOfSpamKeywords + - // Pinging everyone is always treated as spam - pingCount * 5 + Number(hasBareInvite) * 5 - // If it's a job post, then it's probably not spam Number(hasSafeKeywords) * 10; @@ -64,6 +53,7 @@ export default async (bot: Client) => { if (!message.guild || isStaff(author)) { return; } + console.log(msg.content, msg.mentions.everyone, isSpam(message.content)); if (isSpam(message.content)) { const [{ warnings }] = await Promise.all([ @@ -86,7 +76,7 @@ export default async (bot: Client) => { member.kick("Autokicked for spamming"); modLog.send(`Automatically kicked <@${message.author.id}> for spam`); } - } else if (getPingCount(message.content) > 0) { + } else if (msg.mentions.everyone) { await reportUser({ reason: ReportReasons.ping, message: message, From 3bc4c3ac10ee841dcdd9ca20b8ed8dde0111cba1 Mon Sep 17 00:00:00 2001 From: Jesse Jafa Date: Sat, 15 Oct 2022 16:40:41 +0300 Subject: [PATCH 2/2] export isSpam --- app/discord/automod.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/discord/automod.ts b/app/discord/automod.ts index e8c790a..12f0fab 100644 --- a/app/discord/automod.ts +++ b/app/discord/automod.ts @@ -22,7 +22,7 @@ const safeKeywords = ["forhire", "hiring", "remote", "onsite"]; const checkWords = (message: string, wordList: string[]) => message.split(/\b/).some((word) => wordList.includes(word.toLowerCase())); -const isSpam = (content: string, threshold = 4) => { +export const isSpam = (content: string, threshold = 4) => { const numberOfSpamKeywords = spamKeywords.reduce( (accum, spamTrigger) => (spamTrigger.test(content) ? accum + 1 : accum), 0, @@ -53,7 +53,6 @@ export default async (bot: Client) => { if (!message.guild || isStaff(author)) { return; } - console.log(msg.content, msg.mentions.everyone, isSpam(message.content)); if (isSpam(message.content)) { const [{ warnings }] = await Promise.all([