From 59cebca5704fed1d2d985c96b9db8db1b0c08783 Mon Sep 17 00:00:00 2001 From: JandereDev Date: Tue, 12 Oct 2021 17:12:57 +0200 Subject: [PATCH] eeeee --- src/bot/modules/antispam.ts | 12 ++++++++++-- src/struct/antispam/AntispamRule.ts | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/bot/modules/antispam.ts b/src/bot/modules/antispam.ts index af232f8..14c291b 100644 --- a/src/bot/modules/antispam.ts +++ b/src/bot/modules/antispam.ts @@ -1,5 +1,6 @@ import { Message } from "revolt.js/dist/maps/Messages"; import { client } from "../.."; +import AntispamRule from "../../struct/antispam/AntispamRule"; import ModerationAction from "../../struct/antispam/ModerationAction"; import ServerConfig from "../../struct/ServerConfig"; import logger from "../logger"; @@ -26,7 +27,7 @@ async function antispam(message: Message): Promise { if (message.author?.bot != null) break; if (serverRules.whitelist?.users?.includes(message.author_id)) break; if (message.member?.roles?.filter(r => serverRules.whitelist?.roles?.includes(r)).length) break; - if (serverRules.whitelist?.managers !== false && isBotManager(message.member!)) break; + if (serverRules.whitelist?.managers !== false && await isBotManager(message.member!)) break; if (rule.channels?.indexOf(message.channel_id) == -1) break; let store = msgCountStore.get(rule.id)!; @@ -51,7 +52,7 @@ async function antispam(message: Message): Promise { if (!userStore.warnTriggered) { userStore.warnTriggered = true; setTimeout(() => userStore.warnTriggered = false, 5000); - message.channel?.sendMessage(`<@${message.author_id}>, stop spamming (placeholder warn message)`); + message.channel?.sendMessage(getWarnMsg(rule, message)); } break; case ModerationAction.Kick: @@ -67,4 +68,11 @@ async function antispam(message: Message): Promise { return !ruleTriggered; } +function getWarnMsg(rule: AntispamRule, message: Message) { + if (rule.message != null) { + return rule.message + .replace(new RegExp('{{userid}}', 'gi'), message.author_id); + } else return `<@${message.author_id}>, please stop spamming.`; +} + export { antispam } diff --git a/src/struct/antispam/AntispamRule.ts b/src/struct/antispam/AntispamRule.ts index 6c3e0a7..177e082 100644 --- a/src/struct/antispam/AntispamRule.ts +++ b/src/struct/antispam/AntispamRule.ts @@ -7,6 +7,9 @@ import ModerationAction from "./ModerationAction"; * and will delete any additional messages. * * `channels` optionally limits the rule to specific channels. + * + * `message` is an optional custom message sent during punishment. + * '{{userid}}' will be replaced with the user's ID. */ class AntispamRule { id: string; @@ -14,6 +17,7 @@ class AntispamRule { timeframe: number; action: ModerationAction; channels: string[] | null; + message: string | null; } export default AntispamRule;