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

Revise spam handling #166

Merged
merged 6 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
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
54 changes: 37 additions & 17 deletions src/features/autodelete-spam.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ChannelHandlers } from "../types";
import { isStaff } from "../helpers/discord";
import { simplifyString } from "../helpers/modLog";
import { sleep } from "../helpers/misc";

const spamKeywords = ["discord", "nitro", "steam", "free", "gift", "airdrop"];
const spamKeywords = ["nitro", "steam", "free", "gift", "airdrop"];

const safeKeywords = ["hiring", "remote", "onsite"];
const safeKeywords = ["forhire", "hiring", "remote", "onsite"];

const safeDomains = [
"https://discord.com",
Expand All @@ -18,39 +20,57 @@ const safeDomains = [
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 }) => {
if (isStaff(maybeMessage.member)) return;

const msg = maybeMessage.partial
? await maybeMessage.fetch()
: maybeMessage;
if (!msg.guild) return;

const msgHasPingKeywords = ["@everyone", "@here"].some((pingKeyword) =>
msg.content.includes(pingKeyword),
);

const msgHasSpamKeywords = checkWords(msg.content, spamKeywords);
if (msgHasPingKeywords) {
msg
.reply({
embeds: [
{
title: "Tsk tsk.",
description: `Please do **not** try to use \`@here\` or \`@everyone\` - there are ${msg.guild.memberCount} members in Reactiflux. Everybody here is a volunteer, and somebody will respond when they can.`,
color: "#BA0C2F",
},
],
})
.then(async (tsk) => {
await sleep(15);
tsk.delete();
});
}

const content = simplifyString(msg.content);
const words = content.split(" ");
const msgSpamKeywords = words
.map((word) => spamKeywords.includes(word))
.filter(Boolean);

const msgHasNoSafeKeywords = !checkWords(msg.content, safeKeywords);
const msgHasSafeKeywords = checkWords(msg.content, safeKeywords);

const msgHasLink =
msg.content.includes("http") &&
!safeDomains.some((domain) => msg.content.includes(domain));

if (
atLeast(3)(
msgHasPingKeywords,
msgHasSpamKeywords,
msgHasNoSafeKeywords,
msgHasLink,
)
) {
const spamScore =
Number(msgHasLink) +
msgSpamKeywords.length +
// Pinging everyone is always treated as spam
Number(msgHasPingKeywords) * 5 -
// If it's a job post, then it's probably not spam
Number(msgHasSafeKeywords) * 10;

if (spamScore > 3) {
await msg.react("💩");
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/features/autothread.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { differenceInHours, format } from "date-fns";
import { Client, Message, PartialMessage } from "discord.js";
import { Client } from "discord.js";
import { CHANNELS } from "../constants";
import {
constructDiscordLink,
Expand Down
33 changes: 0 additions & 33 deletions src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Message, TextChannel } from "discord.js";
import cooldown from "./cooldown";
import { ChannelHandlers } from "../types";
import { isStaff } from "../helpers/discord";
import { sleep } from "../helpers/misc";

export const EMBED_COLOR = 7506394;

Expand Down Expand Up @@ -637,38 +636,6 @@ Instead:
});
},
},
{
words: ["@here", "@everyone"],
help: "",
category: "Communication",
cooldown: 0,
handleMessage: async (msg) => {
if (!msg || !msg.guild) {
return;
}

const member = await msg.guild.members.fetch(msg.author.id);

if (!member || isStaff(member)) {
return;
}

await msg.react("💩");

const tsk = await msg.reply({
embeds: [
{
title: "Tsk tsk.",
description: `Please do **not** try to use \`@here\` or \`@everyone\` - there are ${msg.guild.memberCount} members in Reactiflux. Everybody here is a volunteer, and somebody will respond when they can.`,
color: "#BA0C2F",
},
],
});
await msg.delete();
await sleep(120);
await tsk.delete();
},
},
{
words: ["!lock"],
help: "",
Expand Down
2 changes: 1 addition & 1 deletion src/features/emojiMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Thanks!

const emojiMod: ChannelHandlers = {
handleReaction: async ({ reaction, user, bot }) => {
const { message, users } = reaction;
const { message } = reaction;
const { author, guild } = message;

if (!guild || !author || author?.id === bot.user?.id) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/modLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const NORMALIZED_CODEPOINTS = /[\u0300-\u036f]/g;
const EMOJI_RANGE =
/[\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF]/g;
const SPECIAL_CHARACTERS =
/[\s≤≥¯˘÷¿…“”‘’«»–—≠±ºª•¶§∞¢£™¡`~`∑´®†¨ˆØ∏\-=_+<>?,./;':"[\]\\{}|!@#$%^&*()]/g;
/[≤≥¯˘÷¿…“”‘’«»–—≠±ºª•¶§∞¢£™¡`~`∑´®†¨ˆØ∏\-=_<>,;'"[\]\\{}|!@#$%^*()]/g;
export const simplifyString = (s: string) =>
s
.toLowerCase()
Expand Down