(options: {
client: any;
replyMessage: Api.Message;
successes: ForwardSuccess[];
sourceEntity: any;
originalMessageIds: number[];
})
| 644 | } |
| 645 | |
| 646 | async function sendTargetFeedback(options: { |
| 647 | client: any; |
| 648 | replyMessage: Api.Message; |
| 649 | successes: ForwardSuccess[]; |
| 650 | sourceEntity: any; |
| 651 | originalMessageIds: number[]; |
| 652 | }) { |
| 653 | const { client, replyMessage, successes, sourceEntity, originalMessageIds } = |
| 654 | options; |
| 655 | if (!successes.length) return; |
| 656 | |
| 657 | const originEntity = sourceEntity ?? replyMessage.peerId; |
| 658 | const sourceNameRaw = getEntityDisplayName(originEntity) ?? "来源对话"; |
| 659 | const sourceLink = buildEntityLink(originEntity); |
| 660 | const sourceName = escapeHtml(sourceNameRaw); |
| 661 | const sourceText = sourceLink |
| 662 | ? `<a href="${escapeAttribute(sourceLink)}">${sourceName}</a>` |
| 663 | : sourceName; |
| 664 | |
| 665 | for (const success of successes) { |
| 666 | const forwardedMessages = success.forwarded; |
| 667 | if (!forwardedMessages || forwardedMessages.length === 0) continue; |
| 668 | const firstForwarded = forwardedMessages[0]; |
| 669 | if (!firstForwarded || typeof firstForwarded.id !== "number") continue; |
| 670 | |
| 671 | const forwardedLinks = buildForwardedLinkTags( |
| 672 | success.entity, |
| 673 | forwardedMessages |
| 674 | ); |
| 675 | const originalLinks = buildMessageLinkTagsByIds( |
| 676 | originEntity, |
| 677 | (originalMessageIds || []).slice(0, forwardedMessages.length) |
| 678 | ); |
| 679 | |
| 680 | const textParts: string[] = []; |
| 681 | textParts.push(`来源:${sourceText}`); |
| 682 | if (originalLinks.length) { |
| 683 | textParts.push(`\n原消息:${originalLinks.join(" ")}`); |
| 684 | } |
| 685 | if (forwardedLinks.length) { |
| 686 | textParts.push(`\n消息:${forwardedLinks.join(" ")}`); |
| 687 | } |
| 688 | |
| 689 | const replyToMsgId = firstForwarded.id; |
| 690 | const topMsgId = success.target.topicId |
| 691 | ? toInt(success.target.topicId) ?? undefined |
| 692 | : undefined; |
| 693 | |
| 694 | try { |
| 695 | await client.sendMessage(success.entity, { |
| 696 | message: textParts.filter(Boolean).join("<br>"), |
| 697 | parseMode: "html", |
| 698 | linkPreview: false, |
| 699 | replyTo: replyToMsgId, |
| 700 | topMsgId, |
| 701 | }); |
| 702 | } catch (error) { |
| 703 | console.warn( |
no test coverage detected