3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Censor: use decoded TSafeRegex for blocked_regex, disable default i flag(!)

This commit is contained in:
Dragory 2019-08-04 15:47:42 +03:00
parent 82a0fa4b43
commit e4f1a6eb15

View file

@ -17,7 +17,7 @@ import { SavedMessage } from "../data/entities/SavedMessage";
import { ZeppelinPlugin } from "./ZeppelinPlugin";
import cloneDeep from "lodash.clonedeep";
import * as t from "io-ts";
import { TSafeRegexString } from "../validatorUtils";
import { TSafeRegex } from "../validatorUtils";
const ConfigSchema = t.type({
filter_zalgo: t.boolean,
@ -32,7 +32,7 @@ const ConfigSchema = t.type({
domain_blacklist: tNullable(t.array(t.string)),
blocked_tokens: tNullable(t.array(t.string)),
blocked_words: tNullable(t.array(t.string)),
blocked_regex: tNullable(t.array(TSafeRegexString)),
blocked_regex: tNullable(t.array(TSafeRegex)),
});
type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
@ -238,12 +238,12 @@ export class CensorPlugin extends ZeppelinPlugin<TConfigSchema> {
}
// Filter regex
const blockedRegex = config.blocked_regex || [];
for (const regexStr of blockedRegex) {
const regex = new RegExp(regexStr, "i");
const blockedRegex: RegExp[] = config.blocked_regex || [];
for (const regex of blockedRegex) {
// Support supplying your own regex flags with the /<regex>/<flags> syntax
// We're testing both the original content and content + attachments/embeds here so regexes that use ^ and $ still match the regular content properly
if (regex.test(savedMessage.data.content) || regex.test(messageContent)) {
this.censorMessage(savedMessage, `blocked regex (\`${regexStr}\`) found`);
this.censorMessage(savedMessage, `blocked regex (\`${regex.source}\`) found`);
return true;
}
}