mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-06-15 18:45:03 +00:00
fix: bandaid fix for regex override merging
This commit is contained in:
parent
dd939895e8
commit
d8fb471b07
5 changed files with 15 additions and 15 deletions
|
@ -2,7 +2,7 @@ import { escapeInlineCode } from "discord.js";
|
|||
import z from "zod/v4";
|
||||
import { allowTimeout } from "../../../RegExpRunner.js";
|
||||
import { getFishFishDomain } from "../../../data/FishFish.js";
|
||||
import { getUrlsInString, zRegex } from "../../../utils.js";
|
||||
import { getUrlsInString, inputPatternToRegExp, zRegex } from "../../../utils.js";
|
||||
import { mergeRegexes } from "../../../utils/mergeRegexes.js";
|
||||
import { mergeWordsIntoRegex } from "../../../utils/mergeWordsIntoRegex.js";
|
||||
import { getTextMatchPartialSummary } from "../functions/getTextMatchPartialSummary.js";
|
||||
|
@ -73,7 +73,7 @@ export const MatchLinksTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
if (trigger.exclude_regex) {
|
||||
if (!regexCache.has(trigger.exclude_regex)) {
|
||||
const toCache = mergeRegexes(trigger.exclude_regex, "i");
|
||||
const toCache = mergeRegexes(trigger.exclude_regex.map(pattern => inputPatternToRegExp(pattern)), "i");
|
||||
regexCache.set(trigger.exclude_regex, toCache);
|
||||
}
|
||||
const regexes = regexCache.get(trigger.exclude_regex)!;
|
||||
|
@ -88,7 +88,7 @@ export const MatchLinksTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
if (trigger.include_regex) {
|
||||
if (!regexCache.has(trigger.include_regex)) {
|
||||
const toCache = mergeRegexes(trigger.include_regex, "i");
|
||||
const toCache = mergeRegexes(trigger.include_regex.map(pattern => inputPatternToRegExp(pattern)), "i");
|
||||
regexCache.set(trigger.include_regex, toCache);
|
||||
}
|
||||
const regexes = regexCache.get(trigger.include_regex)!;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import z from "zod/v4";
|
||||
import { allowTimeout } from "../../../RegExpRunner.js";
|
||||
import { zRegex } from "../../../utils.js";
|
||||
import { inputPatternToRegExp, zRegex } from "../../../utils.js";
|
||||
import { mergeRegexes } from "../../../utils/mergeRegexes.js";
|
||||
import { normalizeText } from "../../../utils/normalizeText.js";
|
||||
import { stripMarkdown } from "../../../utils/stripMarkdown.js";
|
||||
|
@ -38,7 +38,7 @@ export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
|||
|
||||
if (!regexCache.has(trigger)) {
|
||||
const flags = trigger.case_sensitive ? "" : "i";
|
||||
const toCache = mergeRegexes(trigger.patterns, flags);
|
||||
const toCache = mergeRegexes(trigger.patterns.map(pattern => inputPatternToRegExp(pattern)), flags);
|
||||
regexCache.set(trigger, toCache);
|
||||
}
|
||||
const regexes = regexCache.get(trigger)!;
|
||||
|
|
|
@ -7,6 +7,7 @@ import { ISavedMessageEmbedData, SavedMessage } from "../../../data/entities/Sav
|
|||
import {
|
||||
getInviteCodesInString,
|
||||
getUrlsInString,
|
||||
inputPatternToRegExp,
|
||||
isGuildInvite,
|
||||
resolveInvite,
|
||||
resolveMember,
|
||||
|
@ -146,7 +147,8 @@ export async function applyFiltersToMsg(
|
|||
}
|
||||
|
||||
// Filter regex
|
||||
for (const regex of config.blocked_regex || []) {
|
||||
for (const pattern of config.blocked_regex || []) {
|
||||
const regex = inputPatternToRegExp(pattern);
|
||||
// We're testing both the original content and content + attachments/embeds here so regexes that use ^ and $ still match the regular content properly
|
||||
const matches =
|
||||
(await pluginData.state.regexRunner.exec(regex, savedMessage.data.content).catch(allowTimeout)) ||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { GuildPluginData } from "knub";
|
|||
import { allowTimeout } from "../../../RegExpRunner.js";
|
||||
import { LogType } from "../../../data/LogType.js";
|
||||
import { TypedTemplateSafeValueContainer } from "../../../templateFormatter.js";
|
||||
import { MINUTES, isDiscordAPIError } from "../../../utils.js";
|
||||
import { MINUTES, inputPatternToRegExp, isDiscordAPIError } from "../../../utils.js";
|
||||
import { MessageBuffer } from "../../../utils/MessageBuffer.js";
|
||||
import { InternalPosterPlugin } from "../../InternalPoster/InternalPosterPlugin.js";
|
||||
import { ILogTypeData, LogsPluginType, TLogChannel, TLogChannelMap } from "../types.js";
|
||||
|
@ -57,7 +57,8 @@ async function shouldExclude(
|
|||
}
|
||||
|
||||
if (opts.excluded_message_regexes && exclusionData.messageTextContent) {
|
||||
for (const regex of opts.excluded_message_regexes) {
|
||||
for (const pattern of opts.excluded_message_regexes) {
|
||||
const regex = inputPatternToRegExp(pattern);
|
||||
const matches = await pluginData.state.regexRunner
|
||||
.exec(regex, exclusionData.messageTextContent)
|
||||
.catch(allowTimeout);
|
||||
|
|
|
@ -184,16 +184,13 @@ export function inputPatternToRegExp(pattern: string) {
|
|||
}
|
||||
|
||||
export function zRegex<T extends ZodString>(zStr: T) {
|
||||
return zStr.transform((str, ctx) => {
|
||||
return zStr.refine((str) => {
|
||||
try {
|
||||
return inputPatternToRegExp(str);
|
||||
inputPatternToRegExp(str);
|
||||
return true;
|
||||
} catch (err) {
|
||||
if (err instanceof InvalidRegexError) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Invalid regex",
|
||||
});
|
||||
return z.NEVER;
|
||||
return false;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue