mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:51:24 +00:00
Discord: align embed fallback in thread starter parsing
This commit is contained in:
@@ -367,6 +367,34 @@ describe("resolveDiscordMessageText", () => {
|
|||||||
|
|
||||||
expect(text).toBe("hello from content");
|
expect(text).toBe("hello from content");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("joins forwarded snapshot embed title and description when content is empty", () => {
|
||||||
|
const text = resolveDiscordMessageText(
|
||||||
|
asMessage({
|
||||||
|
content: "",
|
||||||
|
rawData: {
|
||||||
|
message_snapshots: [
|
||||||
|
{
|
||||||
|
message: {
|
||||||
|
content: "",
|
||||||
|
embeds: [{ title: "Forwarded title", description: "Forwarded details" }],
|
||||||
|
attachments: [],
|
||||||
|
author: {
|
||||||
|
id: "u2",
|
||||||
|
username: "Bob",
|
||||||
|
discriminator: "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{ includeForwarded: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(text).toContain("[Forwarded message from @Bob]");
|
||||||
|
expect(text).toContain("Forwarded title\nForwarded details");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveDiscordChannelInfo", () => {
|
describe("resolveDiscordChannelInfo", () => {
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ function buildDiscordMediaPlaceholder(params: {
|
|||||||
return attachmentText || stickerText || "";
|
return attachmentText || stickerText || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveDiscordEmbedText(
|
export function resolveDiscordEmbedText(
|
||||||
embed?: { title?: string | null; description?: string | null } | null,
|
embed?: { title?: string | null; description?: string | null } | null,
|
||||||
): string {
|
): string {
|
||||||
const title = embed?.title?.trim() || "";
|
const title = embed?.title?.trim() || "";
|
||||||
|
|||||||
55
src/discord/monitor/threading.starter.test.ts
Normal file
55
src/discord/monitor/threading.starter.test.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { ChannelType, type Client } from "@buape/carbon";
|
||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import {
|
||||||
|
__resetDiscordThreadStarterCacheForTest,
|
||||||
|
resolveDiscordThreadStarter,
|
||||||
|
} from "./threading.js";
|
||||||
|
|
||||||
|
describe("resolveDiscordThreadStarter", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
__resetDiscordThreadStarterCacheForTest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to joined embed title and description when content is empty", async () => {
|
||||||
|
const get = vi.fn().mockResolvedValue({
|
||||||
|
content: " ",
|
||||||
|
embeds: [{ title: "Alert", description: "Details" }],
|
||||||
|
author: { username: "Alice", discriminator: "0" },
|
||||||
|
timestamp: "2026-02-24T12:00:00.000Z",
|
||||||
|
});
|
||||||
|
const client = { rest: { get } } as unknown as Client;
|
||||||
|
|
||||||
|
const result = await resolveDiscordThreadStarter({
|
||||||
|
channel: { id: "thread-1" },
|
||||||
|
client,
|
||||||
|
parentId: "parent-1",
|
||||||
|
parentType: ChannelType.GuildText,
|
||||||
|
resolveTimestampMs: () => 123,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
text: "Alert\nDetails",
|
||||||
|
author: "Alice",
|
||||||
|
timestamp: 123,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prefers starter content over embed fallback text", async () => {
|
||||||
|
const get = vi.fn().mockResolvedValue({
|
||||||
|
content: "starter content",
|
||||||
|
embeds: [{ title: "Alert", description: "Details" }],
|
||||||
|
author: { username: "Alice", discriminator: "0" },
|
||||||
|
});
|
||||||
|
const client = { rest: { get } } as unknown as Client;
|
||||||
|
|
||||||
|
const result = await resolveDiscordThreadStarter({
|
||||||
|
channel: { id: "thread-1" },
|
||||||
|
client,
|
||||||
|
parentId: "parent-1",
|
||||||
|
parentType: ChannelType.GuildText,
|
||||||
|
resolveTimestampMs: () => undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result?.text).toBe("starter content");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -7,7 +7,11 @@ import { buildAgentSessionKey } from "../../routing/resolve-route.js";
|
|||||||
import { truncateUtf16Safe } from "../../utils.js";
|
import { truncateUtf16Safe } from "../../utils.js";
|
||||||
import type { DiscordChannelConfigResolved } from "./allow-list.js";
|
import type { DiscordChannelConfigResolved } from "./allow-list.js";
|
||||||
import type { DiscordMessageEvent } from "./listeners.js";
|
import type { DiscordMessageEvent } from "./listeners.js";
|
||||||
import { resolveDiscordChannelInfo, resolveDiscordMessageChannelId } from "./message-utils.js";
|
import {
|
||||||
|
resolveDiscordChannelInfo,
|
||||||
|
resolveDiscordEmbedText,
|
||||||
|
resolveDiscordMessageChannelId,
|
||||||
|
} from "./message-utils.js";
|
||||||
|
|
||||||
export type DiscordThreadChannel = {
|
export type DiscordThreadChannel = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -172,7 +176,7 @@ export async function resolveDiscordThreadStarter(params: {
|
|||||||
Routes.channelMessage(messageChannelId, params.channel.id),
|
Routes.channelMessage(messageChannelId, params.channel.id),
|
||||||
)) as {
|
)) as {
|
||||||
content?: string | null;
|
content?: string | null;
|
||||||
embeds?: Array<{ description?: string | null }>;
|
embeds?: Array<{ title?: string | null; description?: string | null }>;
|
||||||
member?: { nick?: string | null; displayName?: string | null };
|
member?: { nick?: string | null; displayName?: string | null };
|
||||||
author?: {
|
author?: {
|
||||||
id?: string | null;
|
id?: string | null;
|
||||||
@@ -184,7 +188,9 @@ export async function resolveDiscordThreadStarter(params: {
|
|||||||
if (!starter) {
|
if (!starter) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const text = starter.content?.trim() ?? starter.embeds?.[0]?.description?.trim() ?? "";
|
const content = starter.content?.trim() ?? "";
|
||||||
|
const embedText = resolveDiscordEmbedText(starter.embeds?.[0]);
|
||||||
|
const text = content || embedText;
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user