diff --git a/src/features/autodelete-spam.ts b/src/features/autodelete-spam.ts index 3de791b9..057900f3 100644 --- a/src/features/autodelete-spam.ts +++ b/src/features/autodelete-spam.ts @@ -3,7 +3,25 @@ import { isStaff } from "../helpers/discord"; const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"]; -const atLeastTwo = (...bools: boolean[]) => bools.filter(Boolean).length >= 2; +const safeKeywords = ["hiring", "remote", "onsite"]; + +const safeDomains = [ + "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.split(/\b/).some((word) => wordList.includes(word.toLowerCase())); + +const atLeast = + (count: number) => + (...bools: boolean[]) => + bools.filter(Boolean).length >= count; const autodelete: ChannelHandlers = { handleMessage: async ({ msg: maybeMessage }) => { @@ -17,13 +35,22 @@ const autodelete: ChannelHandlers = { msg.content.includes(pingKeyword), ); - const msgHasSpamKeywords = msg.content - .split(" ") - .some((word) => spamKeywords.includes(word.toLowerCase())); + const msgHasSpamKeywords = checkWords(msg.content, spamKeywords); - const msgHasLink = msg.content.includes("http"); + const msgHasNoSafeKeywords = !checkWords(msg.content, safeKeywords); - if (atLeastTwo(msgHasPingKeywords, msgHasSpamKeywords, msgHasLink)) { + const msgHasLink = + msg.content.includes("http") && + !safeDomains.some((domain) => msg.content.includes(domain)); + + if ( + atLeast(3)( + msgHasPingKeywords, + msgHasSpamKeywords, + msgHasNoSafeKeywords, + msgHasLink, + ) + ) { await msg.react("💩"); } },