mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 06:20:55 +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
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { parseDiscordTarget } from "./targets.js";
|
|
|
|
export function normalizeDiscordMessagingTarget(raw: string): string | undefined {
|
|
// Default bare IDs to channels so routing is stable across tool actions.
|
|
const target = parseDiscordTarget(raw, { defaultKind: "channel" });
|
|
return target?.normalized;
|
|
}
|
|
|
|
/**
|
|
* Normalize a Discord outbound target for delivery. Bare numeric IDs are
|
|
* prefixed with "channel:" to avoid the ambiguous-target error in
|
|
* parseDiscordTarget. All other formats pass through unchanged.
|
|
*/
|
|
export function normalizeDiscordOutboundTarget(
|
|
to?: string,
|
|
): { ok: true; to: string } | { ok: false; error: Error } {
|
|
const trimmed = to?.trim();
|
|
if (!trimmed) {
|
|
return {
|
|
ok: false,
|
|
error: new Error(
|
|
'Discord recipient is required. Use "channel:<id>" for channels or "user:<id>" for DMs.',
|
|
),
|
|
};
|
|
}
|
|
if (/^\d+$/.test(trimmed)) {
|
|
return { ok: true, to: `channel:${trimmed}` };
|
|
}
|
|
return { ok: true, to: trimmed };
|
|
}
|
|
|
|
export function looksLikeDiscordTargetId(raw: string): boolean {
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return false;
|
|
}
|
|
if (/^<@!?\d+>$/.test(trimmed)) {
|
|
return true;
|
|
}
|
|
if (/^(user|channel|discord):/i.test(trimmed)) {
|
|
return true;
|
|
}
|
|
if (/^\d{6,}$/.test(trimmed)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|