all repos — stealth-developers @ 72a01fcc0c16d5c82bfb11894f13ce9669dd349a

feaT(automod): smol improvements
vi v@vt3e.cat
Tue, 07 Apr 2026 03:06:05 +0100
commit

72a01fcc0c16d5c82bfb11894f13ce9669dd349a

parent

ae40d57dc4e856167acb0d8e7f262a0da86089b5

1 files changed, 41 insertions(+), 27 deletions(-)

jump to
M src/automod/index.tssrc/automod/index.ts

@@ -1,29 +1,44 @@

import { hasManagerPermissions } from "@/utils/discord/permissions"; import type { Client, Message, Snowflake } from "discord.js"; -type UserId = Snowflake; - type Pending = { - channels: Set<string>; + channels: Set<Snowflake>; timer: NodeJS.Timeout; }; -const pendingReports = new Map<UserId, Pending>(); -const cooldowns = new Map<UserId, NodeJS.Timeout>(); +const pendingReports = new Map<Snowflake, Pending>(); +const cooldowns = new Map<Snowflake, NodeJS.Timeout>(); async function getLogChannel(client: Client) { - return client.channels.fetch("1478940790112915486"); + return client.channels.fetch("1477508937287864431"); } +type AutomodResult = { delete: true } | null; +type AutomodFunction = ( + client: Client, + message: Message, +) => Promise<AutomodResult>; + export async function handleMessage(client: Client, message: Message) { if (message.author.bot || !message.guildId) return; - handleSpamLinks(client, message); + const automodFunctions: AutomodFunction[] = [handleSpamLinks]; + + for (const func of automodFunctions) { + const result = await func(client, message); + if (result?.delete) { + await message.delete().catch(() => null); + break; + } + } } -async function handleSpamLinks(client: Client, message: Message) { - if (message.author.bot || !message.guildId || !message.member) return; - if (await hasManagerPermissions(message.member)) return; - if (message.channelId === "1378529224192819250") return; +async function handleSpamLinks( + client: Client, + message: Message, +): Promise<AutomodResult> { + if (message.author.bot || !message.guildId || !message.member) return null; + if (await hasManagerPermissions(message.member)) return null; + if (message.channelId === "1478940790112915486") return null; const { content } = message; const blacklisted = [

@@ -32,29 +47,26 @@ "discordapp.com/invite/",

"discord.com/invite/", ]; - if (!blacklisted.some((link) => content.includes(link))) return; - - if (message.channel.isSendable()) { - message.reply( - `<@${message.author.id}> your message contained an invite link and was deleted to prevent phishing attempts.`, - ); - } - - const logChannel = await getLogChannel(client); + if (!blacklisted.some((link) => content.includes(link))) return null; if (cooldowns.has(message.author.id)) { - if (message.deletable) message.delete(); - return; + return { delete: true }; } const existing = pendingReports.get(message.author.id); if (!existing) { + const content = [ + `<@${message.author.id}>, your message contained an invite link and was deleted to prevent phishing attempts.`, + "Keep in mind, we don't allow advertising other servers here.", + ]; + await message.reply(content.join(" ")); + + const logChannel = await getLogChannel(client); if (logChannel?.isSendable()) { await message.forward(logChannel); logChannel.send( `Deleted a message from <@${message.author.id}> in <#${message.channelId}> containing a potential phishing link.`, ); - message.delete(); } const timer = setTimeout(

@@ -66,7 +78,7 @@ channels: new Set([message.channelId]),

timer, }); - return; + return { delete: true }; } existing.channels.add(message.channelId);

@@ -76,9 +88,11 @@ existing.timer = setTimeout(

() => flushReport(client, message.author.id), 30_000, ); + + return { delete: true }; } -async function flushReport(client: Client, authorId: UserId) { +async function flushReport(client: Client, authorId: Snowflake) { const pending = pendingReports.get(authorId); if (!pending) return;

@@ -91,8 +105,8 @@

const channels = Array.from(pending.channels); const channelMentions = channels.map((c) => `<#${c}>`).join(", "); - await logChannel.send( - `<@${authorId}> posted invite/phishing links across ${channels.length} channel(s): ${channelMentions}`, + logChannel.send( + `<@${authorId}> posted links in channels: ${channelMentions}`, ); const cooldownTimer = setTimeout(