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

Function searchEditAndDeleteMyMessages

dme/dme.ts:1004–1222  ·  view source on GitHub ↗

* 搜索并处理用户消息的主函数 - 防撤回模式(-f参数)流式处理版本

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

Source from the content-addressed store, hash-verified

1002 topicRootId?: number
1003): Promise<{
1004 processedCount: number;
1005 actualCount: number;
1006 editedCount: number;
1007}> {
1008 // 收藏夹(保存的消息)专用快速删除
1009 if (isSavedMessagesPeer(chatEntity, myId)) {
1010 console.log("[DME] 检测到收藏夹会话,直接按数量删除");
1011 return await deleteInSavedMessages(client, chatEntity, userRequestedCount);
1012 }
1013
1014 // 检查是否为频道且有管理权限
1015 const isChannel = chatEntity.className === "Channel";
1016 if (isChannel) {
1017 console.log(`[DME] 检测到频道,检查管理员权限...`);
1018 try {
1019 const me = await safeGetMe(client);
1020 if (!me) return { processedCount: 0, actualCount: 0, editedCount: 0 };
1021 const participant = await client.invoke(
1022 new Api.channels.GetParticipant({
1023 channel: chatEntity,
1024 participant: me.id,
1025 })
1026 );
1027
1028 const isCreator =
1029 participant.participant.className === "ChannelParticipantCreator";
1030 const isBroadcast = (chatEntity as any).broadcast === true;
1031 if (isCreator && isBroadcast) {
1032 console.log(`[DME] 检测到私人频道且为频道主,直接按数量删除`);
1033 return await deleteInSavedMessages(client, chatEntity, userRequestedCount);
1034 }
1035
1036 const isAdmin =
1037 participant.participant.className === "ChannelParticipantAdmin" ||
1038 participant.participant.className === "ChannelParticipantCreator";
1039
1040 if (isAdmin) {
1041 console.log(`[DME] 拥有频道管理权限,但仍使用普通模式避免误删别人消息`);
1042 } else {
1043 console.log(`[DME] 无频道管理权限,使用普通模式`);
1044 }
1045 } catch (error) {
1046 console.log(`[DME] 权限检查失败,使用普通模式:`, error);
1047 }
1048 }
1049
1050 // 频道/超级群里“以频道身份发言”的消息通常不带个人 senderId,
1051 // 直接改用 out 消息遍历模式,避免流式搜索漏删。
1052 if (isChannel) {
1053 console.log(`[DME] 频道会话启用出站消息遍历模式(支持频道身份发言)`);
1054 return await traditionalStreamProcessing(client, chatEntity, myId, userRequestedCount, true, topicRootId);
1055 }
1056
1057 // 检测是否为受限群组(禁止转发和复制)
1058 const isRestricted = await isRestrictedGroup(client, chatEntity);
1059 if (isRestricted) {
1060 console.log(`[DME] 检测到受限群组,切换到传统遍历模式`);
1061 return await traditionalStreamProcessing(client, chatEntity, myId, userRequestedCount, true, topicRootId);

Callers 1

runOneRoundFunction · 0.85

Calls 11

isSavedMessagesPeerFunction · 0.85
deleteInSavedMessagesFunction · 0.85
isRestrictedGroupFunction · 0.85
getTrollImageFunction · 0.85
isMessageInTopicFunction · 0.85
deleteMessagesWithRetryFunction · 0.85
errorMethod · 0.80
sleepFunction · 0.70

Tested by

no test coverage detected