MCPcopy Create free account
hub / github.com/Epic0522/Codex-Remote-Contact / fetchOneBotForwardContent

Function fetchOneBotForwardContent

src/server.js:5588–5630  ·  view source on GitHub ↗
(forwardId)

Source from the content-addressed store, hash-verified

5586}
5587
5588async function fetchOneBotForwardContent(forwardId) {
5589 const response = await fetch(`${oneBotApiBase}/get_forward_msg`, {
5590 method: "POST",
5591 headers: { "content-type": "application/json" },
5592 body: JSON.stringify({ id: String(forwardId) })
5593 });
5594 const body = await response.json().catch(() => ({}));
5595 const messages = Array.isArray(body.data?.messages)
5596 ? body.data.messages
5597 : Array.isArray(body.data)
5598 ? body.data
5599 : [];
5600 if (!response.ok || body.status !== "ok" || messages.length === 0) {
5601 throw new Error(`Unable to fetch forward QQ message ${forwardId}`);
5602 }
5603
5604 const lines = [];
5605 const images = [];
5606 for (const node of messages) {
5607 const senderName = node?.sender?.card || node?.sender?.nickname || node?.nickname || "群友";
5608 const segments = Array.isArray(node?.content)
5609 ? node.content
5610 : Array.isArray(node?.message)
5611 ? node.message
5612 : Array.isArray(node?.data?.content)
5613 ? node.data.content
5614 : [];
5615 const text = segments
5616 .filter((segment) => segment?.type === "text")
5617 .map((segment) => segment.data?.text ?? "")
5618 .join("")
5619 .trim();
5620 const nodeImages = extractOneBotImageInputs({ message: segments });
5621 if (text) lines.push(`${senderName}:${text}`);
5622 else if (nodeImages.length > 0) lines.push(`${senderName}:[图片]`);
5623 images.push(...nodeImages);
5624 }
5625
5626 return {
5627 text: lines.join("\n").trim(),
5628 images: dedupeQqImages(images)
5629 };
5630}
5631
5632function dedupeQqImages(images) {
5633 const seen = new Set();

Callers 1

fetchOneBotMessageFunction · 0.85

Calls 2

extractOneBotImageInputsFunction · 0.85
dedupeQqImagesFunction · 0.85

Tested by

no test coverage detected