This commit is contained in:
JandereDev 2021-10-12 17:12:57 +02:00
parent a82d03f5cc
commit 59cebca570
No known key found for this signature in database
GPG key ID: 5D5E18ACB990F57A
2 changed files with 14 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import { Message } from "revolt.js/dist/maps/Messages"; import { Message } from "revolt.js/dist/maps/Messages";
import { client } from "../.."; import { client } from "../..";
import AntispamRule from "../../struct/antispam/AntispamRule";
import ModerationAction from "../../struct/antispam/ModerationAction"; import ModerationAction from "../../struct/antispam/ModerationAction";
import ServerConfig from "../../struct/ServerConfig"; import ServerConfig from "../../struct/ServerConfig";
import logger from "../logger"; import logger from "../logger";
@ -26,7 +27,7 @@ async function antispam(message: Message): Promise<boolean> {
if (message.author?.bot != null) break; if (message.author?.bot != null) break;
if (serverRules.whitelist?.users?.includes(message.author_id)) break; if (serverRules.whitelist?.users?.includes(message.author_id)) break;
if (message.member?.roles?.filter(r => serverRules.whitelist?.roles?.includes(r)).length) 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; if (rule.channels?.indexOf(message.channel_id) == -1) break;
let store = msgCountStore.get(rule.id)!; let store = msgCountStore.get(rule.id)!;
@ -51,7 +52,7 @@ async function antispam(message: Message): Promise<boolean> {
if (!userStore.warnTriggered) { if (!userStore.warnTriggered) {
userStore.warnTriggered = true; userStore.warnTriggered = true;
setTimeout(() => userStore.warnTriggered = false, 5000); setTimeout(() => userStore.warnTriggered = false, 5000);
message.channel?.sendMessage(`<@${message.author_id}>, stop spamming (placeholder warn message)`); message.channel?.sendMessage(getWarnMsg(rule, message));
} }
break; break;
case ModerationAction.Kick: case ModerationAction.Kick:
@ -67,4 +68,11 @@ async function antispam(message: Message): Promise<boolean> {
return !ruleTriggered; 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 } export { antispam }

View file

@ -7,6 +7,9 @@ import ModerationAction from "./ModerationAction";
* and will delete any additional messages. * and will delete any additional messages.
* *
* `channels` optionally limits the rule to specific channels. * `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 { class AntispamRule {
id: string; id: string;
@ -14,6 +17,7 @@ class AntispamRule {
timeframe: number; timeframe: number;
action: ModerationAction; action: ModerationAction;
channels: string[] | null; channels: string[] | null;
message: string | null;
} }
export default AntispamRule; export default AntispamRule;