mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +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)");
|
||||
});
|
||||
|
||||
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", () => {
|
||||
|
||||
@@ -403,17 +403,32 @@ function buildDiscordMediaPlaceholder(params: {
|
||||
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(
|
||||
message: Message,
|
||||
options?: { fallbackText?: string; includeForwarded?: boolean },
|
||||
): string {
|
||||
const embedText = resolveDiscordEmbedText(
|
||||
(message.embeds?.[0] as { title?: string | null; description?: string | null } | undefined) ??
|
||||
null,
|
||||
);
|
||||
const baseText =
|
||||
message.content?.trim() ||
|
||||
buildDiscordMediaPlaceholder({
|
||||
attachments: message.attachments ?? undefined,
|
||||
stickers: resolveDiscordMessageStickers(message),
|
||||
}) ||
|
||||
message.embeds?.[0]?.description ||
|
||||
embedText ||
|
||||
options?.fallbackText?.trim() ||
|
||||
"";
|
||||
if (!options?.includeForwarded) {
|
||||
@@ -477,8 +492,7 @@ function resolveDiscordSnapshotMessageText(snapshot: DiscordSnapshotMessage): st
|
||||
attachments: snapshot.attachments ?? undefined,
|
||||
stickers: resolveDiscordSnapshotStickers(snapshot),
|
||||
});
|
||||
const embed = snapshot.embeds?.[0];
|
||||
const embedText = embed?.description?.trim() || embed?.title?.trim() || "";
|
||||
const embedText = resolveDiscordEmbedText(snapshot.embeds?.[0]);
|
||||
return content || attachmentText || embedText || "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user