refactor(feishu): dedupe mention regex escaping

This commit is contained in:
Peter Steinberger
2026-02-19 15:04:40 +01:00
parent b54ba3391b
commit f4b288b8f7
3 changed files with 58 additions and 12 deletions

View File

@@ -7,13 +7,20 @@ import {
DEFAULT_GROUP_HISTORY_LIMIT,
type HistoryEntry,
} from "openclaw/plugin-sdk";
import type { FeishuMessageContext, FeishuMediaInfo, ResolvedFeishuAccount } from "./types.js";
import type { DynamicAgentCreationConfig } from "./types.js";
import { resolveFeishuAccount } from "./accounts.js";
import { createFeishuClient } from "./client.js";
import { tryRecordMessage } from "./dedup.js";
import { maybeCreateDynamicAgent } from "./dynamic-agent.js";
import { normalizeFeishuExternalKey } from "./external-keys.js";
import { downloadMessageResourceFeishu } from "./media.js";
import { extractMentionTargets, extractMessageBody, isMentionForwardRequest } from "./mention.js";
import {
escapeRegExp,
extractMentionTargets,
extractMessageBody,
isMentionForwardRequest,
} from "./mention.js";
import {
resolveFeishuGroupConfig,
resolveFeishuReplyPolicy,
@@ -23,8 +30,6 @@ import {
import { createFeishuReplyDispatcher } from "./reply-dispatcher.js";
import { getFeishuRuntime } from "./runtime.js";
import { getMessageFeishu, sendMessageFeishu } from "./send.js";
import type { FeishuMessageContext, FeishuMediaInfo, ResolvedFeishuAccount } from "./types.js";
import type { DynamicAgentCreationConfig } from "./types.js";
// --- Permission error extraction ---
// Extract permission grant URL from Feishu API error response.
@@ -199,21 +204,17 @@ function checkBotMentioned(event: FeishuMessageEvent, botOpenId?: string): boole
return false;
}
function escapeRegExp(s: string): string {
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function stripBotMention(
export function stripBotMention(
text: string,
mentions?: FeishuMessageEvent["message"]["mentions"],
): string {
if (!mentions || mentions.length === 0) return text;
let result = text;
for (const mention of mentions) {
result = result.replace(new RegExp(`@${escapeRegExp(mention.name)}\\s*`, "g"), "").trim();
result = result.replace(new RegExp(escapeRegExp(mention.key), "g"), "").trim();
result = result.replace(new RegExp(`@${escapeRegExp(mention.name)}\\s*`, "g"), "");
result = result.replace(new RegExp(escapeRegExp(mention.key), "g"), "");
}
return result;
return result.trim();
}
/**