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

54 lines
1.5 KiB
TypeScript

import type { Guild, Message, User } from "@buape/carbon";
import { resolveTimestampMs } from "./format.js";
import { resolveDiscordSenderIdentity } from "./sender-identity.js";
export type DiscordReplyContext = {
id: string;
channelId: string;
sender: string;
body: string;
timestamp?: number;
};
export function resolveReplyContext(
message: Message,
resolveDiscordMessageText: (message: Message, options?: { includeForwarded?: boolean }) => string,
): DiscordReplyContext | null {
const referenced = message.referencedMessage;
if (!referenced?.author) {
return null;
}
const referencedText = resolveDiscordMessageText(referenced, {
includeForwarded: true,
});
if (!referencedText) {
return null;
}
const sender = resolveDiscordSenderIdentity({
author: referenced.author,
pluralkitInfo: null,
});
return {
id: referenced.id,
channelId: referenced.channelId,
sender: sender.tag ?? sender.label ?? "unknown",
body: referencedText,
timestamp: resolveTimestampMs(referenced.timestamp),
};
}
export function buildDirectLabel(author: User, tagOverride?: string) {
const username =
tagOverride?.trim() || resolveDiscordSenderIdentity({ author, pluralkitInfo: null }).tag;
return `${username ?? "unknown"} user id:${author.id}`;
}
export function buildGuildLabel(params: {
guild?: Guild<true> | Guild;
channelName: string;
channelId: string;
}) {
const { guild, channelName, channelId } = params;
return `${guild?.name ?? "Guild"} #${channelName} channel id:${channelId}`;
}