mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Spam: add max characters filter
This commit is contained in:
parent
b949b52bac
commit
4cdfa15613
1 changed files with 43 additions and 22 deletions
|
@ -6,7 +6,7 @@ import {
|
||||||
getUrlsInString,
|
getUrlsInString,
|
||||||
getUserMentions,
|
getUserMentions,
|
||||||
stripObjectToScalars,
|
stripObjectToScalars,
|
||||||
trimLines
|
trimLines,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import { LogType } from "../data/LogType";
|
import { LogType } from "../data/LogType";
|
||||||
import { GuildLogs } from "../data/GuildLogs";
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
|
@ -26,7 +26,8 @@ enum RecentActionType {
|
||||||
Attachment,
|
Attachment,
|
||||||
Emoji,
|
Emoji,
|
||||||
Newline,
|
Newline,
|
||||||
Censor
|
Censor,
|
||||||
|
Character,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IRecentAction {
|
interface IRecentAction {
|
||||||
|
@ -75,8 +76,11 @@ export class SpamPlugin extends Plugin {
|
||||||
max_attachments: null,
|
max_attachments: null,
|
||||||
max_emojis: null,
|
max_emojis: null,
|
||||||
max_newlines: null,
|
max_newlines: null,
|
||||||
max_duplicates: null
|
max_duplicates: null,
|
||||||
|
max_characters: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Default override to make mods immune to the spam filter
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
level: ">=50",
|
level: ">=50",
|
||||||
|
@ -87,10 +91,11 @@ export class SpamPlugin extends Plugin {
|
||||||
max_attachments: null,
|
max_attachments: null,
|
||||||
max_emojis: null,
|
max_emojis: null,
|
||||||
max_newlines: null,
|
max_newlines: null,
|
||||||
max_duplicates: null
|
max_duplicates: null,
|
||||||
}
|
max_characters: null,
|
||||||
}
|
},
|
||||||
]
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +127,7 @@ export class SpamPlugin extends Plugin {
|
||||||
channelId: string,
|
channelId: string,
|
||||||
savedMessage: SavedMessage,
|
savedMessage: SavedMessage,
|
||||||
timestamp: number,
|
timestamp: number,
|
||||||
count = 1
|
count = 1,
|
||||||
) {
|
) {
|
||||||
this.recentActions.push({ type, userId, channelId, savedMessage, timestamp, count });
|
this.recentActions.push({ type, userId, channelId, savedMessage, timestamp, count });
|
||||||
}
|
}
|
||||||
|
@ -172,7 +177,7 @@ export class SpamPlugin extends Plugin {
|
||||||
type: RecentActionType,
|
type: RecentActionType,
|
||||||
spamConfig: any,
|
spamConfig: any,
|
||||||
actionCount: number,
|
actionCount: number,
|
||||||
description: string
|
description: string,
|
||||||
) {
|
) {
|
||||||
if (actionCount === 0) return;
|
if (actionCount === 0) return;
|
||||||
|
|
||||||
|
@ -199,7 +204,7 @@ export class SpamPlugin extends Plugin {
|
||||||
type,
|
type,
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
since
|
since,
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the user tripped the spam filter...
|
// If the user tripped the spam filter...
|
||||||
|
@ -222,7 +227,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const additionalMessages = await this.savedMessages.getUserMessagesByChannelAfterId(
|
const additionalMessages = await this.savedMessages.getUserMessagesByChannelAfterId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
lastDetectedMsgId
|
lastDetectedMsgId,
|
||||||
);
|
);
|
||||||
additionalMessages.forEach(m => msgIds.push(m.id));
|
additionalMessages.forEach(m => msgIds.push(m.id));
|
||||||
|
|
||||||
|
@ -266,7 +271,7 @@ export class SpamPlugin extends Plugin {
|
||||||
description,
|
description,
|
||||||
limit: spamConfig.count,
|
limit: spamConfig.count,
|
||||||
interval: spamConfig.interval,
|
interval: spamConfig.interval,
|
||||||
archiveUrl
|
archiveUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
const theCase: Case = await this.actions.fire("createCase", {
|
const theCase: Case = await this.actions.fire("createCase", {
|
||||||
|
@ -274,7 +279,7 @@ export class SpamPlugin extends Plugin {
|
||||||
modId: this.bot.user.id,
|
modId: this.bot.user.id,
|
||||||
type: caseType,
|
type: caseType,
|
||||||
reason: caseText,
|
reason: caseText,
|
||||||
automatic: true
|
automatic: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// For mutes, also set the mute's case id (for !mutes)
|
// For mutes, also set the mute's case id (for !mutes)
|
||||||
|
@ -286,7 +291,7 @@ export class SpamPlugin extends Plugin {
|
||||||
err => {
|
err => {
|
||||||
console.error("Error while detecting spam:");
|
console.error("Error while detecting spam:");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +300,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const spamConfig = this.configValueForMemberIdAndChannelId(
|
const spamConfig = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_censor"
|
"max_censor",
|
||||||
);
|
);
|
||||||
if (spamConfig) {
|
if (spamConfig) {
|
||||||
this.logAndDetectSpam(savedMessage, RecentActionType.Censor, spamConfig, 1, "too many censored messages");
|
this.logAndDetectSpam(savedMessage, RecentActionType.Censor, spamConfig, 1, "too many censored messages");
|
||||||
|
@ -308,7 +313,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const maxMessages = this.configValueForMemberIdAndChannelId(
|
const maxMessages = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_messages"
|
"max_messages",
|
||||||
);
|
);
|
||||||
if (maxMessages) {
|
if (maxMessages) {
|
||||||
this.logAndDetectSpam(savedMessage, RecentActionType.Message, maxMessages, 1, "too many messages");
|
this.logAndDetectSpam(savedMessage, RecentActionType.Message, maxMessages, 1, "too many messages");
|
||||||
|
@ -317,7 +322,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const maxMentions = this.configValueForMemberIdAndChannelId(
|
const maxMentions = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_mentions"
|
"max_mentions",
|
||||||
);
|
);
|
||||||
const mentions = savedMessage.data.content
|
const mentions = savedMessage.data.content
|
||||||
? [...getUserMentions(savedMessage.data.content), ...getRoleMentions(savedMessage.data.content)]
|
? [...getUserMentions(savedMessage.data.content), ...getRoleMentions(savedMessage.data.content)]
|
||||||
|
@ -329,7 +334,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const maxLinks = this.configValueForMemberIdAndChannelId(
|
const maxLinks = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_links"
|
"max_links",
|
||||||
);
|
);
|
||||||
if (maxLinks && savedMessage.data.content) {
|
if (maxLinks && savedMessage.data.content) {
|
||||||
const links = getUrlsInString(savedMessage.data.content);
|
const links = getUrlsInString(savedMessage.data.content);
|
||||||
|
@ -339,7 +344,7 @@ export class SpamPlugin extends Plugin {
|
||||||
const maxAttachments = this.configValueForMemberIdAndChannelId(
|
const maxAttachments = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_attachments"
|
"max_attachments",
|
||||||
);
|
);
|
||||||
if (maxAttachments && savedMessage.data.attachments) {
|
if (maxAttachments && savedMessage.data.attachments) {
|
||||||
this.logAndDetectSpam(
|
this.logAndDetectSpam(
|
||||||
|
@ -347,14 +352,14 @@ export class SpamPlugin extends Plugin {
|
||||||
RecentActionType.Attachment,
|
RecentActionType.Attachment,
|
||||||
maxAttachments,
|
maxAttachments,
|
||||||
savedMessage.data.attachments.length,
|
savedMessage.data.attachments.length,
|
||||||
"too many attachments"
|
"too many attachments",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxEmoji = this.configValueForMemberIdAndChannelId(
|
const maxEmoji = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_emojis"
|
"max_emojis",
|
||||||
);
|
);
|
||||||
if (maxEmoji && savedMessage.data.content) {
|
if (maxEmoji && savedMessage.data.content) {
|
||||||
const emojiCount = getEmojiInString(savedMessage.data.content).length;
|
const emojiCount = getEmojiInString(savedMessage.data.content).length;
|
||||||
|
@ -364,13 +369,29 @@ export class SpamPlugin extends Plugin {
|
||||||
const maxNewlines = this.configValueForMemberIdAndChannelId(
|
const maxNewlines = this.configValueForMemberIdAndChannelId(
|
||||||
savedMessage.user_id,
|
savedMessage.user_id,
|
||||||
savedMessage.channel_id,
|
savedMessage.channel_id,
|
||||||
"max_newlines"
|
"max_newlines",
|
||||||
);
|
);
|
||||||
if (maxNewlines && savedMessage.data.content) {
|
if (maxNewlines && savedMessage.data.content) {
|
||||||
const newlineCount = (savedMessage.data.content.match(/\n/g) || []).length;
|
const newlineCount = (savedMessage.data.content.match(/\n/g) || []).length;
|
||||||
this.logAndDetectSpam(savedMessage, RecentActionType.Newline, maxNewlines, newlineCount, "too many newlines");
|
this.logAndDetectSpam(savedMessage, RecentActionType.Newline, maxNewlines, newlineCount, "too many newlines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxCharacters = this.configValueForMemberIdAndChannelId(
|
||||||
|
savedMessage.user_id,
|
||||||
|
savedMessage.channel_id,
|
||||||
|
"max_characters",
|
||||||
|
);
|
||||||
|
if (maxCharacters && savedMessage.data.content) {
|
||||||
|
const characterCount = [...savedMessage.data.content.trim()].length;
|
||||||
|
this.logAndDetectSpam(
|
||||||
|
savedMessage,
|
||||||
|
RecentActionType.Character,
|
||||||
|
maxCharacters,
|
||||||
|
characterCount,
|
||||||
|
"too many characters",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Max duplicates
|
// TODO: Max duplicates
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue