Skip to content
Draft
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
15 changes: 2 additions & 13 deletions app/discord/automod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 numberOfSpamKeywords = spamKeywords.reduce(
(accum, spamTrigger) => (spamTrigger.test(content) ? accum + 1 : accum),
0,
Expand All @@ -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;
Expand Down Expand Up @@ -86,7 +75,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,
Expand Down