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

Function traditionalStreamProcessing

dme/dme.ts:679–870  ·  view source on GitHub ↗

* 传统遍历消息流式处理 - 适用于禁止转发和复制的群组

(
  client: TelegramClient,
  chatEntity: any,
  myId: bigint,
  userRequestedCount: number,
  isAntiRecallMode: boolean = false,
  topicRootId?: number
)

Source from the content-addressed store, hash-verified

677 isAntiRecallMode: boolean = false,
678 topicRootId?: number
679): Promise<{
680 processedCount: number;
681 actualCount: number;
682 editedCount: number;
683}> {
684 console.log(`[DME] 使用传统遍历消息流式处理模式`);
685
686 const targetCount = userRequestedCount === 999999 ? Infinity : userRequestedCount;
687 const trollImagePath = isAntiRecallMode ? await getTrollImage() : null;
688 const sendAsIdentity =
689 chatEntity.className === "Channel"
690 ? await getSendAsIdentitySet(client, chatEntity)
691 : { typedKeys: new Set<string>(), rawIds: new Set<string>() };
692
693 let totalProcessed = 0;
694 let totalEdited = 0;
695 let totalDeleted = 0;
696 let offsetId = 0;
697 let consecutiveEmptyBatches = 0;
698 const maxEmptyBatches =
699 chatEntity.className === "Channel" ? CONFIG.CHANNEL_EMPTY_BATCH_LIMIT : 3;
700 const HISTORY_BATCH = 100; // 每批获取历史消息数量
701
702 // 传统模式:逐批获取历史消息,筛选自己的消息进行处理
703 while (totalProcessed < targetCount && consecutiveEmptyBatches < maxEmptyBatches) {
704 try {
705 // 获取历史消息
706 const history = await client.invoke(
707 new Api.messages.GetHistory({
708 peer: chatEntity,
709 offsetId,
710 offsetDate: 0,
711 addOffset: 0,
712 limit: HISTORY_BATCH,
713 maxId: 0,
714 minId: 0,
715 hash: 0 as any,
716 })
717 );
718
719 const allMessages: any[] = (history as any).messages || [];
720 const validMessages = allMessages.filter((m: any) => m.className === "Message");
721
722 if (validMessages.length === 0) {
723 consecutiveEmptyBatches++;
724 console.log(`[DME] 空批次 ${consecutiveEmptyBatches}/${maxEmptyBatches}`);
725 await sleep(CONFIG.DELAYS.SEARCH);
726 continue;
727 }
728
729 // 筛选出自己的消息
730 const myMessages = validMessages.filter(
731 (m: any) =>
732 isMessageInTopic(m, topicRootId) &&
733 isMyMessageByIdentity(
734 m,
735 myId,
736 sendAsIdentity.typedKeys,

Callers 2

quickDeleteMyMessagesFunction · 0.85

Calls 9

getTrollImageFunction · 0.85
getSendAsIdentitySetFunction · 0.85
isMessageInTopicFunction · 0.85
isMyMessageByIdentityFunction · 0.85
deleteMessagesWithRetryFunction · 0.85
errorMethod · 0.80
sleepFunction · 0.70

Tested by

no test coverage detected