mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 08:31:35 +00:00
fix(discord): include embed title in fallback text (#26907)
This commit is contained in:
@@ -323,6 +323,50 @@ describe("resolveDiscordMessageText", () => {
|
|||||||
|
|
||||||
expect(text).toBe("<media:sticker> (1 sticker)");
|
expect(text).toBe("<media:sticker> (1 sticker)");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses embed title when content is empty", () => {
|
||||||
|
const text = resolveDiscordMessageText(
|
||||||
|
asMessage({
|
||||||
|
content: "",
|
||||||
|
embeds: [{ title: "Breaking" }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(text).toBe("Breaking");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses embed description when content is empty", () => {
|
||||||
|
const text = resolveDiscordMessageText(
|
||||||
|
asMessage({
|
||||||
|
content: "",
|
||||||
|
embeds: [{ description: "Details" }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(text).toBe("Details");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("joins embed title and description when content is empty", () => {
|
||||||
|
const text = resolveDiscordMessageText(
|
||||||
|
asMessage({
|
||||||
|
content: "",
|
||||||
|
embeds: [{ title: "Breaking", description: "Details" }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(text).toBe("Breaking\nDetails");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers message content over embed fallback text", () => {
|
||||||
|
const text = resolveDiscordMessageText(
|
||||||
|
asMessage({
|
||||||
|
content: "hello from content",
|
||||||
|
embeds: [{ title: "Breaking", description: "Details" }],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(text).toBe("hello from content");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveDiscordChannelInfo", () => {
|
describe("resolveDiscordChannelInfo", () => {
|
||||||
|
|||||||
@@ -403,17 +403,32 @@ function buildDiscordMediaPlaceholder(params: {
|
|||||||
return attachmentText || stickerText || "";
|
return attachmentText || stickerText || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveDiscordEmbedText(
|
||||||
|
embed?: { title?: string | null; description?: string | null } | null,
|
||||||
|
): string {
|
||||||
|
const title = embed?.title?.trim() || "";
|
||||||
|
const description = embed?.description?.trim() || "";
|
||||||
|
if (title && description) {
|
||||||
|
return `${title}\n${description}`;
|
||||||
|
}
|
||||||
|
return title || description || "";
|
||||||
|
}
|
||||||
|
|
||||||
export function resolveDiscordMessageText(
|
export function resolveDiscordMessageText(
|
||||||
message: Message,
|
message: Message,
|
||||||
options?: { fallbackText?: string; includeForwarded?: boolean },
|
options?: { fallbackText?: string; includeForwarded?: boolean },
|
||||||
): string {
|
): string {
|
||||||
|
const embedText = resolveDiscordEmbedText(
|
||||||
|
(message.embeds?.[0] as { title?: string | null; description?: string | null } | undefined) ??
|
||||||
|
null,
|
||||||
|
);
|
||||||
const baseText =
|
const baseText =
|
||||||
message.content?.trim() ||
|
message.content?.trim() ||
|
||||||
buildDiscordMediaPlaceholder({
|
buildDiscordMediaPlaceholder({
|
||||||
attachments: message.attachments ?? undefined,
|
attachments: message.attachments ?? undefined,
|
||||||
stickers: resolveDiscordMessageStickers(message),
|
stickers: resolveDiscordMessageStickers(message),
|
||||||
}) ||
|
}) ||
|
||||||
message.embeds?.[0]?.description ||
|
embedText ||
|
||||||
options?.fallbackText?.trim() ||
|
options?.fallbackText?.trim() ||
|
||||||
"";
|
"";
|
||||||
if (!options?.includeForwarded) {
|
if (!options?.includeForwarded) {
|
||||||
@@ -477,8 +492,7 @@ function resolveDiscordSnapshotMessageText(snapshot: DiscordSnapshotMessage): st
|
|||||||
attachments: snapshot.attachments ?? undefined,
|
attachments: snapshot.attachments ?? undefined,
|
||||||
stickers: resolveDiscordSnapshotStickers(snapshot),
|
stickers: resolveDiscordSnapshotStickers(snapshot),
|
||||||
});
|
});
|
||||||
const embed = snapshot.embeds?.[0];
|
const embedText = resolveDiscordEmbedText(snapshot.embeds?.[0]);
|
||||||
const embedText = embed?.description?.trim() || embed?.title?.trim() || "";
|
|
||||||
return content || attachmentText || embedText || "";
|
return content || attachmentText || embedText || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user