Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark several domains as safe #164

Merged
merged 6 commits into from
Jan 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/features/autodelete-spam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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("💩");
}
},
Expand Down