mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 13:30:48 +00:00
* refactor: move Discord channel implementation to extensions/discord/src/ Move all Discord source files from src/discord/ to extensions/discord/src/, following the extension migration pattern. Source files in src/discord/ are replaced with re-export shims. Channel-plugin files from src/channels/plugins/*/discord* are similarly moved and shimmed. - Copy all .ts source files preserving subdirectory structure (monitor/, voice/) - Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues) - Fix all relative imports to use correct paths from new location - Create re-export shims at original locations for backward compatibility - Delete test files from shim locations (tests live in extension now) - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate extension files outside src/ - Update write-plugin-sdk-entry-dts.ts to match new declaration output paths * fix: add importOriginal to thread-bindings session-meta mock for extensions test * style: fix formatting in thread-bindings lifecycle test
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import type { MsgContext } from "../../../src/auto-reply/templating.js";
|
|
import { normalizeChatType } from "../../../src/channels/chat-type.js";
|
|
|
|
export function normalizeExplicitDiscordSessionKey(
|
|
sessionKey: string,
|
|
ctx: Pick<MsgContext, "ChatType" | "From" | "SenderId">,
|
|
): string {
|
|
let normalized = sessionKey.trim().toLowerCase();
|
|
if (normalizeChatType(ctx.ChatType) !== "direct") {
|
|
return normalized;
|
|
}
|
|
|
|
normalized = normalized.replace(/^(discord:)dm:/, "$1direct:");
|
|
normalized = normalized.replace(/^(agent:[^:]+:discord:)dm:/, "$1direct:");
|
|
const match = normalized.match(/^((?:agent:[^:]+:)?)discord:channel:([^:]+)$/);
|
|
if (!match) {
|
|
return normalized;
|
|
}
|
|
|
|
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;
|
|
return directId && directId === match[2] ? `${match[1]}discord:direct:${match[2]}` : normalized;
|
|
}
|