mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Short circuit on short messages
This commit is contained in:
parent
19e07a64b5
commit
4ec3f30069
@ -41,12 +41,13 @@ export class MentionSpam extends Protection {
|
||||
|
||||
public checkMentions(body: unknown|undefined, htmlBody: unknown|undefined, mentionArray: unknown|undefined): boolean {
|
||||
const max = this.settings.maxMentions.value;
|
||||
const minMessageLength = max * 3; // "@:a"
|
||||
if (Array.isArray(mentionArray)) {
|
||||
if (mentionArray.length > this.settings.maxMentions.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (typeof body === "string") {
|
||||
if (typeof body === "string" && body.length > minMessageLength) {
|
||||
let found = 0;
|
||||
for (const word of body.split(/\s/)) {
|
||||
if (USER_ID_SIGIL_REGEX.test(word.trim())) {
|
||||
@ -56,7 +57,7 @@ export class MentionSpam extends Protection {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof htmlBody === "string") {
|
||||
if (typeof htmlBody === "string" && htmlBody.length > minMessageLength) {
|
||||
let found = 0;
|
||||
for (const word of htmlBody.split(/\s/)) {
|
||||
if (USER_ID_SIGIL_REGEX.test(word.trim())) {
|
||||
|
Loading…
Reference in New Issue
Block a user