MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / executeSummary

Function executeSummary

sum/sum.ts:727–787  ·  view source on GitHub ↗
(task: SummaryTask)

Source from the content-addressed store, hash-verified

725 // 构建消息文本,包含文件信息
726 let textContent = message.message || "";
727 const fileName = extractFileName(message);
728 if (fileName) {
729 textContent = textContent
730 ? `${textContent} [文件: ${fileName}]`
731 : `[文件: ${fileName}]`;
732 }
733
734 if (textContent) {
735 messageData.push({
736 text: `[${time}] ${sender}: ${textContent}`,
737 content: message.message || "",
738 telegramLink: link,
739 urls,
740 fileName: fileName || undefined,
741 });
742 }
743 }
744
745 return messageData.reverse();
746}
747
748// 获取群消息(按时间范围)
749async function getGroupMessagesByTime(
750 chatId: string,
751 hours: number,
752): Promise<MessageData[]> {
753 const client = await getGlobalClient();
754 if (!client) throw new Error("Telegram 客户端未初始化");
755
756 const now = Math.floor(Date.now() / 1000);
757 const startTime = now - hours * 3600;
758
759 const messages = await safeGetMessages(client, chatId, { limit: 100 });
760
761 // 获取群组 username(如果有)
762 let chatUsername: string | undefined;
763 try {
764 const entity = await client.getEntity(chatId);
765 chatUsername = (entity as any).username;
766 } catch (e) {
767 // 忽略错误,使用私有链接格式
768 }
769
770 const messageData: MessageData[] = [];
771 for (const msg of messages) {
772 const message = msg as any;
773 if (message.date < startTime) continue;
774 if (!message.message && !message.media) continue;
775
776 const sender =
777 message.sender?.firstName || message.sender?.username || "未知用户";
778 const time = formatDate(new Date(message.date * 1000));
779 const link = buildMessageLink(chatId, message.id, chatUsername);
780 const urls = extractUrlsFromEntities(message);
781
782 // 构建消息文本,包含文件信息
783 let textContent = message.message || "";
784 const fileName = extractFileName(message);

Callers 2

scheduleTaskFunction · 0.85
SummaryPluginClass · 0.85

Calls 7

getGroupMessagesByTimeFunction · 0.85
getGroupMessagesFunction · 0.85
summarizeMessagesFunction · 0.85
wrapWithSpoilerFunction · 0.85
getDBFunction · 0.70
htmlEscapeFunction · 0.70
formatDateFunction · 0.70

Tested by

no test coverage detected