From 3f145610732ab9110e461832cf13b5c74517d3fe Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 14:05:15 +0100 Subject: [PATCH 1/6] Mark several domains as safe --- src/features/autodelete-spam.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index 3de791b9..5d37fc83 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -3,6 +3,14 @@ import { isStaff } from "../helpers/discord"; const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"]; +const safeDomains = [ + "reactiflux.com", + "github.com", + "mozilla.org", + "reactjs.org", + "nextjs.org", +]; + const atLeastTwo = (...bools: boolean[]) => bools.filter(Boolean).length >= 2; const autodelete: ChannelHandlers = { @@ -21,7 +29,9 @@ const autodelete: ChannelHandlers = { .split(" ") .some((word) => spamKeywords.includes(word.toLowerCase())); - const msgHasLink = msg.content.includes("http"); + const msgHasLink = + msg.content.includes("http") && + !safeDomains.some((domain) => msg.content.includes(domain)); if (atLeastTwo(msgHasPingKeywords, msgHasSpamKeywords, msgHasLink)) { await msg.react("💩"); From dab12be3f87b8a90a6c516de2faa9f07ee1f69c0 Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 14:17:13 +0100 Subject: [PATCH 2/6] several keywords reduce the likelyhood of a message being spam --- src/features/autodelete-spam.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index 5d37fc83..b88c69b4 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -3,6 +3,8 @@ import { isStaff } from "../helpers/discord"; const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"]; +const safeKeywords = ["hiring", "remote", "onsite"]; + const safeDomains = [ "reactiflux.com", "github.com", @@ -11,7 +13,10 @@ const safeDomains = [ "nextjs.org", ]; -const atLeastTwo = (...bools: boolean[]) => bools.filter(Boolean).length >= 2; +const atLeast = + (count: number) => + (...bools: boolean[]) => + bools.filter(Boolean).length >= count; const autodelete: ChannelHandlers = { handleMessage: async ({ msg: maybeMessage }) => { @@ -26,14 +31,25 @@ const autodelete: ChannelHandlers = { ); const msgHasSpamKeywords = msg.content - .split(" ") + .split(/\b/) .some((word) => spamKeywords.includes(word.toLowerCase())); + const msgHasNoSafeKeywords = !msg.content + .split(/\b/) + .some((word) => safeKeywords.includes(word.toLowerCase())); + const msgHasLink = msg.content.includes("http") && !safeDomains.some((domain) => msg.content.includes(domain)); - if (atLeastTwo(msgHasPingKeywords, msgHasSpamKeywords, msgHasLink)) { + if ( + atLeast(3)( + msgHasPingKeywords, + msgHasSpamKeywords, + msgHasNoSafeKeywords, + msgHasLink, + ) + ) { await msg.react("💩"); } }, From bbb4c204843b1490ba2f5da34a0774ea3022d618 Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 20:33:56 +0100 Subject: [PATCH 3/6] create checkWords function --- src/features/autodelete-spam.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index b88c69b4..5e3c8e1d 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -13,6 +13,10 @@ const safeDomains = [ "nextjs.org", ]; +const checkWords = (message: string, wordList: string[]) => message + .split(/\b/) + .some((word) => wordList.includes(word.toLowerCase())); + const atLeast = (count: number) => (...bools: boolean[]) => @@ -30,13 +34,9 @@ const autodelete: ChannelHandlers = { msg.content.includes(pingKeyword), ); - const msgHasSpamKeywords = msg.content - .split(/\b/) - .some((word) => spamKeywords.includes(word.toLowerCase())); + const msgHasSpamKeywords = checkWords(msg.content, spamKeywords); - const msgHasNoSafeKeywords = !msg.content - .split(/\b/) - .some((word) => safeKeywords.includes(word.toLowerCase())); + const msgHasNoSafeKeywords = !checkWords(msg.content, safeKeywords); const msgHasLink = msg.content.includes("http") && From 03e147c0ce9afbc3c9abe13ef631b0e3d5568eac Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 20:34:27 +0100 Subject: [PATCH 4/6] discord.com is also safe --- src/features/autodelete-spam.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index 5e3c8e1d..07c7d7d0 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -6,6 +6,7 @@ const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"]; const safeKeywords = ["hiring", "remote", "onsite"]; const safeDomains = [ + "discord.com", "reactiflux.com", "github.com", "mozilla.org", From 07d2a001c8c0fcba2dbfd9f0b87b1ee928c70ef4 Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 20:37:39 +0100 Subject: [PATCH 5/6] use full domains --- src/features/autodelete-spam.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index 07c7d7d0..b1dd9407 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -6,12 +6,13 @@ const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"]; const safeKeywords = ["hiring", "remote", "onsite"]; const safeDomains = [ - "discord.com", - "reactiflux.com", - "github.com", - "mozilla.org", - "reactjs.org", - "nextjs.org", + "https://discord.com", + "https://www.reactiflux.com", + "https://github.com", + "https://developer.mozilla.org", + "https://reactjs.org", + "https://beta.reactjs.org", + "https://nextjs.org", ]; const checkWords = (message: string, wordList: string[]) => message From f2deb13864a790e40a0f7c733b890fde71f100c2 Mon Sep 17 00:00:00 2001 From: Evert Bouw Date: Tue, 18 Jan 2022 20:37:55 +0100 Subject: [PATCH 6/6] fmt --- src/features/autodelete-spam.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index b1dd9407..057900f3 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -15,9 +15,8 @@ const safeDomains = [ "https://nextjs.org", ]; -const checkWords = (message: string, wordList: string[]) => message - .split(/\b/) - .some((word) => wordList.includes(word.toLowerCase())); +const checkWords = (message: string, wordList: string[]) => + message.split(/\b/).some((word) => wordList.includes(word.toLowerCase())); const atLeast = (count: number) =>