惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
Y
Y Combinator Blog
博客园_首页
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
B
Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
WordPress大学
WordPress大学
L
LangChain Blog
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(discord): add outbound mention aliases · openclaw/ope...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -5,9 +5,12 @@ import {

55

} from "openclaw/plugin-sdk/text-runtime";

66

import { resolveDiscordDirectoryUserId } from "./directory-cache.js";

778+

type DiscordMentionAliasesConfig = Record<string, string>;

9+810

const MARKDOWN_CODE_SEGMENT_PATTERN = /```[\s\S]*?```|`[^`\n]*`/g;

911

const MENTION_CANDIDATE_PATTERN = /(^|[\s([{"'.,;:!?])@([a-z0-9_.-]{2,32}(?:#[0-9]{4})?)/gi;

1012

const DISCORD_RESERVED_MENTIONS = new Set(["everyone", "here"]);

13+

const DISCORD_DISCRIMINATOR_SUFFIX = /#\d{4}$/;

11141215

function normalizeSnowflake(value: string | number | bigint): string | null {

1316

const text = normalizeOptionalStringifiedId(value) ?? "";

@@ -43,7 +46,58 @@ export function formatMention(params: {

4346

return `<#${target.id}>`;

4447

}

454846-

function rewritePlainTextMentions(text: string, accountId?: string | null): string {

49+

function normalizeHandleKey(raw: string): string | null {

50+

let handle = normalizeOptionalString(raw) ?? "";

51+

if (!handle) {

52+

return null;

53+

}

54+

if (handle.startsWith("@")) {

55+

handle = normalizeOptionalString(handle.slice(1)) ?? "";

56+

}

57+

if (!handle || /\s/.test(handle)) {

58+

return null;

59+

}

60+

return normalizeLowercaseStringOrEmpty(handle);

61+

}

62+63+

function resolveConfiguredMentionAlias(

64+

handle: string,

65+

mentionAliases?: DiscordMentionAliasesConfig | null,

66+

): string | undefined {

67+

const key = normalizeHandleKey(handle);

68+

if (!key || !mentionAliases) {

69+

return undefined;

70+

}

71+

const withoutDiscriminator = key.replace(DISCORD_DISCRIMINATOR_SUFFIX, "");

72+

for (const [rawAlias, rawUserId] of Object.entries(mentionAliases)) {

73+

const alias = normalizeHandleKey(rawAlias);

74+

if (!alias) {

75+

continue;

76+

}

77+

const aliasWithoutDiscriminator = alias.replace(DISCORD_DISCRIMINATOR_SUFFIX, "");

78+

if (

79+

alias === key ||

80+

(withoutDiscriminator && withoutDiscriminator !== key && alias === withoutDiscriminator) ||

81+

(aliasWithoutDiscriminator &&

82+

aliasWithoutDiscriminator !== alias &&

83+

aliasWithoutDiscriminator === key)

84+

) {

85+

const userId = normalizeSnowflake(rawUserId);

86+

if (userId) {

87+

return userId;

88+

}

89+

}

90+

}

91+

return undefined;

92+

}

93+94+

function rewritePlainTextMentions(

95+

text: string,

96+

params: {

97+

accountId?: string | null;

98+

mentionAliases?: DiscordMentionAliasesConfig | null;

99+

},

100+

): string {

47101

if (!text.includes("@")) {

48102

return text;

49103

}

@@ -56,10 +110,12 @@ function rewritePlainTextMentions(text: string, accountId?: string | null): stri

56110

if (DISCORD_RESERVED_MENTIONS.has(lookup)) {

57111

return match;

58112

}

59-

const userId = resolveDiscordDirectoryUserId({

60-

accountId,

61-

handle,

62-

});

113+

const userId =

114+

resolveConfiguredMentionAlias(handle, params.mentionAliases) ??

115+

resolveDiscordDirectoryUserId({

116+

accountId: params.accountId,

117+

handle,

118+

});

63119

if (!userId) {

64120

return match;

65121

}

@@ -69,7 +125,10 @@ function rewritePlainTextMentions(text: string, accountId?: string | null): stri

6912570126

export function rewriteDiscordKnownMentions(

71127

text: string,

72-

params: { accountId?: string | null },

128+

params: {

129+

accountId?: string | null;

130+

mentionAliases?: DiscordMentionAliasesConfig | null;

131+

},

73132

): string {

74133

if (!text.includes("@")) {

75134

return text;

@@ -79,10 +138,10 @@ export function rewriteDiscordKnownMentions(

79138

MARKDOWN_CODE_SEGMENT_PATTERN.lastIndex = 0;

80139

for (const match of text.matchAll(MARKDOWN_CODE_SEGMENT_PATTERN)) {

81140

const matchIndex = match.index ?? 0;

82-

rewritten += rewritePlainTextMentions(text.slice(offset, matchIndex), params.accountId);

141+

rewritten += rewritePlainTextMentions(text.slice(offset, matchIndex), params);

83142

rewritten += match[0];

84143

offset = matchIndex + match[0].length;

85144

}

86-

rewritten += rewritePlainTextMentions(text.slice(offset), params.accountId);

145+

rewritten += rewritePlainTextMentions(text.slice(offset), params);

87146

return rewritten;

88147

}