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

Function adaptiveBatchDelete

dme/dme.ts:562–606  ·  view source on GitHub ↗

* 自适应批次删除函数

(
  client: TelegramClient,
  chatEntity: any,
  messageIds: number[]
)

Source from the content-addressed store, hash-verified

560 let deletedCount = 0;
561 let failedCount = 0;
562 let currentBatchSize: number = CONFIG.BATCH_SIZE;
563
564 for (let i = 0; i < messageIds.length; i += currentBatchSize) {
565 const batch = messageIds.slice(i, i + currentBatchSize);
566
567 try {
568 await deleteMessagesWithRetry(client, chatEntity, batch);
569 deletedCount += batch.length;
570
571 // 成功则可以适当增加批次大小
572 if (currentBatchSize < CONFIG.MAX_BATCH_SIZE) {
573 currentBatchSize = Math.min(currentBatchSize + 5, CONFIG.MAX_BATCH_SIZE);
574 }
575
576 console.log(`[DME] 成功删除批次 ${batch.length} 条,当前批次大小: ${currentBatchSize}`);
577 await sleep(CONFIG.DELAYS.BATCH);
578
579 } catch (error: any) {
580 console.log(`[DME] 批次删除失败,减少批次大小:`, error.message);
581
582 // 失败则减少批次大小
583 currentBatchSize = Math.max(Math.floor(currentBatchSize / 2), CONFIG.MIN_BATCH_SIZE);
584
585 if (currentBatchSize <= CONFIG.MIN_BATCH_SIZE && batch.length === 1) {
586 // 单条消息删除失败,跳过
587 failedCount += 1;
588 console.log(`[DME] 跳过无法删除的消息: ${batch[0]}`);
589 } else {
590 // 重新尝试当前批次(使用更小的批次大小)
591 i -= batch.length;
592 }
593
594 await sleep(CONFIG.DELAYS.RETRY);
595 }
596 }
597
598 return { deletedCount, failedCount };
599}
600
601/**
602 * 收藏夹直接按数量删除(不做媒体编辑)
603 */
604async function deleteInSavedMessages(
605 client: TelegramClient,
606 chatEntity: any,
607 userRequestedCount: number
608): Promise<{ processedCount: number; actualCount: number; editedCount: number }> {
609 const targetCount =

Callers 1

quickDeleteMyMessagesFunction · 0.85

Calls 2

deleteMessagesWithRetryFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected