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

Function quickDeleteMyMessages

dme/dme.ts:875–999  ·  view source on GitHub ↗

* 快速删除模式 - 直接调用官方API删除消息

(
  client: TelegramClient,
  chatEntity: any,
  myId: bigint,
  userRequestedCount: number,
  topicRootId?: number
)

Source from the content-addressed store, hash-verified

873 topicRootId?: number
874): Promise<{
875 processedCount: number;
876 actualCount: number;
877 editedCount: number;
878}> {
879 // 频道/超级群里“以频道身份发言”的消息通常不带个人 senderId,
880 // 直接改用 out 消息遍历模式,避免快速搜索漏删。
881 if (chatEntity.className === "Channel") {
882 console.log(`[DME] 频道会话启用出站消息遍历模式(支持频道身份发言)`);
883 return await traditionalStreamProcessing(client, chatEntity, myId, userRequestedCount, false, topicRootId);
884 }
885
886 // 检测是否为受限群组(禁止转发和复制)
887 const isRestricted = await isRestrictedGroup(client, chatEntity);
888 if (isRestricted) {
889 console.log(`[DME] 检测到受限群组,切换到传统遍历模式`);
890 return await traditionalStreamProcessing(client, chatEntity, myId, userRequestedCount, false, topicRootId);
891 }
892
893 console.log(`[DME] 使用快速删除模式`);
894
895 const targetCount =
896 userRequestedCount === CONFIG.UNLIMITED_REQUEST_COUNT
897 ? Infinity
898 : userRequestedCount;
899 let offsetId = 0;
900 let searchFailCount = 0;
901 const maxSearchFails = 2;
902 let totalMatched = 0;
903 let totalDeleted = 0;
904 let hasSearchResult = false;
905
906 // 流式搜索并删除:避免 allMyMessages 大数组导致堆内存膨胀
907 while (targetCount === Infinity || totalMatched < targetCount) {
908 const searchLimit =
909 targetCount === Infinity
910 ? CONFIG.SEARCH_LIMIT
911 : Math.min(CONFIG.SEARCH_LIMIT, targetCount - totalMatched);
912
913 try {
914 const searchResult = await client.invoke(
915 new Api.messages.Search({
916 peer: chatEntity,
917 q: "",
918 fromId: await client.getInputEntity(myId.toString()),
919 ...(typeof topicRootId === "number" ? { topMsgId: topicRootId } : {}),
920 filter: new Api.InputMessagesFilterEmpty(),
921 minDate: 0,
922 maxDate: 0,
923 offsetId: offsetId,
924 addOffset: 0,
925 limit: searchLimit,
926 maxId: 0,
927 minId: 0,
928 hash: 0 as any
929 })
930 );
931
932 const resultMessages = (searchResult as any).messages;

Callers 1

runOneRoundFunction · 0.85

Calls 6

isRestrictedGroupFunction · 0.85
isMessageInTopicFunction · 0.85
adaptiveBatchDeleteFunction · 0.85
errorMethod · 0.80
sleepFunction · 0.70

Tested by

no test coverage detected