openclaw/extensions/discord/src/monitor/sender-identity.ts
scoootscooob 5682ec37fa
refactor: move Discord channel implementation to extensions/ (#45660)
* 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
2026-03-14 02:53:57 -07:00

83 lines
2.4 KiB
TypeScript

import type { User } from "@buape/carbon";
import type { PluralKitMessageInfo } from "../pluralkit.js";
import { formatDiscordUserTag } from "./format.js";
export type DiscordSenderIdentity = {
id: string;
name?: string;
tag?: string;
label: string;
isPluralKit: boolean;
pluralkit?: {
memberId: string;
memberName?: string;
systemId?: string;
systemName?: string;
};
};
type DiscordWebhookMessageLike = {
webhookId?: string | null;
webhook_id?: string | null;
};
export function resolveDiscordWebhookId(message: DiscordWebhookMessageLike): string | null {
const candidate = message.webhookId ?? message.webhook_id;
return typeof candidate === "string" && candidate.trim() ? candidate.trim() : null;
}
export function resolveDiscordSenderIdentity(params: {
author: User;
// oxlint-disable-next-line typescript/no-explicit-any
member?: any;
pluralkitInfo?: PluralKitMessageInfo | null;
}): DiscordSenderIdentity {
const pkInfo = params.pluralkitInfo ?? null;
const pkMember = pkInfo?.member ?? undefined;
const pkSystem = pkInfo?.system ?? undefined;
const memberId = pkMember?.id?.trim();
const memberNameRaw = pkMember?.display_name ?? pkMember?.name ?? "";
const memberName = memberNameRaw?.trim();
if (memberId && memberName) {
const systemName = pkSystem?.name?.trim();
const label = systemName ? `${memberName} (PK:${systemName})` : `${memberName} (PK)`;
return {
id: memberId,
name: memberName,
tag: pkMember?.name?.trim() || undefined,
label,
isPluralKit: true,
pluralkit: {
memberId,
memberName,
systemId: pkSystem?.id?.trim() || undefined,
systemName,
},
};
}
const senderTag = formatDiscordUserTag(params.author);
const senderDisplay =
params.member?.nickname ?? params.author.globalName ?? params.author.username;
const senderLabel =
senderDisplay && senderTag && senderDisplay !== senderTag
? `${senderDisplay} (${senderTag})`
: (senderDisplay ?? senderTag ?? params.author.id);
return {
id: params.author.id,
name: params.author.username ?? undefined,
tag: senderTag,
label: senderLabel,
isPluralKit: false,
};
}
export function resolveDiscordSenderLabel(params: {
author: User;
// oxlint-disable-next-line typescript/no-explicit-any
member?: any;
pluralkitInfo?: PluralKitMessageInfo | null;
}): string {
return resolveDiscordSenderIdentity(params).label;
}