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

59 lines
1.4 KiB
TypeScript

import { resolveFetch } from "../../../src/infra/fetch.js";
const PLURALKIT_API_BASE = "https://api.pluralkit.me/v2";
export type DiscordPluralKitConfig = {
enabled?: boolean;
token?: string;
};
export type PluralKitSystemInfo = {
id: string;
name?: string | null;
tag?: string | null;
};
export type PluralKitMemberInfo = {
id: string;
name?: string | null;
display_name?: string | null;
};
export type PluralKitMessageInfo = {
id: string;
original?: string | null;
sender?: string | null;
system?: PluralKitSystemInfo | null;
member?: PluralKitMemberInfo | null;
};
export async function fetchPluralKitMessageInfo(params: {
messageId: string;
config?: DiscordPluralKitConfig;
fetcher?: typeof fetch;
}): Promise<PluralKitMessageInfo | null> {
if (!params.config?.enabled) {
return null;
}
const fetchImpl = resolveFetch(params.fetcher);
if (!fetchImpl) {
return null;
}
const headers: Record<string, string> = {};
if (params.config.token?.trim()) {
headers.Authorization = params.config.token.trim();
}
const res = await fetchImpl(`${PLURALKIT_API_BASE}/messages/${params.messageId}`, {
headers,
});
if (res.status === 404) {
return null;
}
if (!res.ok) {
const text = await res.text().catch(() => "");
const detail = text.trim() ? `: ${text.trim()}` : "";
throw new Error(`PluralKit API failed (${res.status})${detail}`);
}
return (await res.json()) as PluralKitMessageInfo;
}