mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:54:32 +00:00
refactor(discord): extract session key normalization
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { MsgContext } from "../../auto-reply/templating.js";
|
||||
import { normalizeChatType } from "../../channels/chat-type.js";
|
||||
import { normalizeExplicitDiscordSessionKey } from "../../discord/session-key-normalization.js";
|
||||
import {
|
||||
buildAgentMainSessionKey,
|
||||
DEFAULT_AGENT_ID,
|
||||
@@ -29,24 +29,7 @@ export function deriveSessionKey(scope: SessionScope, ctx: MsgContext) {
|
||||
export function resolveSessionKey(scope: SessionScope, ctx: MsgContext, mainKey?: string) {
|
||||
const explicit = ctx.SessionKey?.trim();
|
||||
if (explicit) {
|
||||
let normalized = explicit.toLowerCase();
|
||||
if (normalizeChatType(ctx.ChatType) === "direct") {
|
||||
normalized = normalized.replace(/^(agent:[^:]+:discord:)dm:/, "$1direct:");
|
||||
const match = normalized.match(/^((?:agent:[^:]+:)?)discord:channel:([^:]+)$/);
|
||||
if (match) {
|
||||
const from = (ctx.From ?? "").trim().toLowerCase();
|
||||
const senderId = (ctx.SenderId ?? "").trim().toLowerCase();
|
||||
const fromDiscordId =
|
||||
from.startsWith("discord:") && !from.includes(":channel:") && !from.includes(":group:")
|
||||
? from.slice("discord:".length)
|
||||
: "";
|
||||
const directId = senderId || fromDiscordId;
|
||||
if (directId && directId === match[2]) {
|
||||
normalized = `${match[1]}discord:direct:${match[2]}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return normalized;
|
||||
return normalizeExplicitDiscordSessionKey(explicit, ctx);
|
||||
}
|
||||
const raw = deriveSessionKey(scope, ctx);
|
||||
if (scope === "global") {
|
||||
|
||||
Reference in New Issue
Block a user