mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 09:21:12 +00:00
Discord: CV2! (#16364)
This commit is contained in:
@@ -1,20 +1,50 @@
|
||||
import { Separator, TextDisplay, type TopLevelComponents } from "@buape/carbon";
|
||||
import type { ChannelId } from "../../channels/plugins/types.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { DiscordUiContainer } from "../../discord/ui.js";
|
||||
|
||||
export type CrossContextComponentsBuilder = (message: string) => TopLevelComponents[];
|
||||
|
||||
export type CrossContextComponentsFactory = (params: {
|
||||
originLabel: string;
|
||||
message: string;
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
}) => TopLevelComponents[];
|
||||
|
||||
export type ChannelMessageAdapter = {
|
||||
supportsEmbeds: boolean;
|
||||
buildCrossContextEmbeds?: (originLabel: string) => unknown[];
|
||||
supportsComponentsV2: boolean;
|
||||
buildCrossContextComponents?: CrossContextComponentsFactory;
|
||||
};
|
||||
|
||||
type CrossContextContainerParams = {
|
||||
originLabel: string;
|
||||
message: string;
|
||||
cfg: OpenClawConfig;
|
||||
accountId?: string | null;
|
||||
};
|
||||
|
||||
class CrossContextContainer extends DiscordUiContainer {
|
||||
constructor({ originLabel, message, cfg, accountId }: CrossContextContainerParams) {
|
||||
const trimmed = message.trim();
|
||||
const components = [] as Array<TextDisplay | Separator>;
|
||||
if (trimmed) {
|
||||
components.push(new TextDisplay(message));
|
||||
components.push(new Separator({ divider: true, spacing: "small" }));
|
||||
}
|
||||
components.push(new TextDisplay(`*From ${originLabel}*`));
|
||||
super({ cfg, accountId, components });
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_ADAPTER: ChannelMessageAdapter = {
|
||||
supportsEmbeds: false,
|
||||
supportsComponentsV2: false,
|
||||
};
|
||||
|
||||
const DISCORD_ADAPTER: ChannelMessageAdapter = {
|
||||
supportsEmbeds: true,
|
||||
buildCrossContextEmbeds: (originLabel: string) => [
|
||||
{
|
||||
description: `From ${originLabel}`,
|
||||
},
|
||||
supportsComponentsV2: true,
|
||||
buildCrossContextComponents: ({ originLabel, message, cfg, accountId }) => [
|
||||
new CrossContextContainer({ originLabel, message, cfg, accountId }),
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user