fix: revert regex batching
This commit is contained in:
parent
04c81727fb
commit
ef53ee64c6
1 changed files with 11 additions and 24 deletions
|
@ -13,8 +13,6 @@ interface MatchResultType {
|
||||||
type: MatchableTextType;
|
type: MatchableTextType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinedRegexCache: WeakMap<any, RegExp> = new WeakMap();
|
|
||||||
|
|
||||||
export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
||||||
configType: t.type({
|
configType: t.type({
|
||||||
patterns: t.array(TRegex),
|
patterns: t.array(TRegex),
|
||||||
|
@ -46,20 +44,6 @@ export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trigger.patterns.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!combinedRegexCache.has(trigger)) {
|
|
||||||
const combinedPattern = trigger.patterns.map((p) => `(?:${p.source})`).join("|");
|
|
||||||
const combinedRegex = new RegExp(combinedPattern, trigger.case_sensitive ? "" : "i");
|
|
||||||
if (trigger.patterns.some((r) => r.source === "。")) {
|
|
||||||
console.log("!! COMBINED PATTERN !!", combinedPattern);
|
|
||||||
}
|
|
||||||
combinedRegexCache.set(trigger, combinedRegex);
|
|
||||||
}
|
|
||||||
const regex = combinedRegexCache.get(trigger)!;
|
|
||||||
|
|
||||||
for await (let [type, str] of matchMultipleTextTypesOnMessage(pluginData, trigger, context.message)) {
|
for await (let [type, str] of matchMultipleTextTypesOnMessage(pluginData, trigger, context.message)) {
|
||||||
if (trigger.strip_markdown) {
|
if (trigger.strip_markdown) {
|
||||||
str = stripMarkdown(str);
|
str = stripMarkdown(str);
|
||||||
|
@ -69,14 +53,17 @@ export const MatchRegexTrigger = automodTrigger<MatchResultType>()({
|
||||||
str = normalizeText(str);
|
str = normalizeText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matches = await pluginData.state.regexRunner.exec(regex, str).catch(allowTimeout);
|
for (const sourceRegex of trigger.patterns) {
|
||||||
if (matches?.length) {
|
const regex = new RegExp(sourceRegex.source, trigger.case_sensitive && !sourceRegex.ignoreCase ? "" : "i");
|
||||||
return {
|
const matches = await pluginData.state.regexRunner.exec(regex, str).catch(allowTimeout);
|
||||||
extra: {
|
if (matches?.length) {
|
||||||
pattern: "<temporarily hidden>",
|
return {
|
||||||
type,
|
extra: {
|
||||||
},
|
pattern: sourceRegex.source,
|
||||||
};
|
type,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue