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

Method cleanDeletedPM

clean/clean.ts:172–256  ·  view source on GitHub ↗
(client: any, msg: Api.Message, deleteDialogs: boolean = false)

Source from the content-addressed store, hash-verified

170
171// 私聊已注销账号清理 - 修复版:直接移除整个对话
172 private async cleanDeletedPM(client: any, msg: Api.Message, deleteDialogs: boolean = false): Promise<void> {
173 await this.editMessage(msg, deleteDialogs
174 ? "🔍 正在扫描并从对话列表中移除已注销账号..."
175 : "🔍 正在扫描私聊已注销账号...");
176
177 const deletedUsers: Array<{id: string, username?: string}> = [];
178
179 try {
180 const dialogsMain = await client.getDialogs({});
181 let dialogsArchived: any[] = [];
182 try {
183 dialogsArchived = await client.getDialogs({ folderId: 1 });
184 } catch (error: any) {
185 console.error(`[Clean] 获取归档对话失败:`, error?.message || error);
186 }
187
188 const dialogByUserId = new Map<string, any>();
189 const dialogs = [...(dialogsMain || []), ...(dialogsArchived || [])];
190
191 for (const dialog of dialogs) {
192 if (dialog.isUser && dialog.entity instanceof Api.User && dialog.entity.deleted) {
193 const user = dialog.entity;
194 const userId = user.id.toString();
195
196 if (!dialogByUserId.has(userId)) {
197 dialogByUserId.set(userId, dialog);
198 deletedUsers.push({
199 id: userId,
200 username: user.username || "已注销账号"
201 });
202 }
203 }
204 }
205
206 if (deleteDialogs) {
207 for (const [userId, dialog] of dialogByUserId.entries()) {
208 try {
209 /**
210 * 修复核心:
211 * 1. 使用 dialog.inputEntity 确保 ID 类型在 API 层级完全匹配。
212 * 2. 不传任何参数(默认不开启 revoke),直接从本地对话列表中移除该会话。
213 * 3. 针对已注销账号,开启 revoke 反而会导致删除失败。
214 */
215 await client.deleteDialog(dialog.inputEntity);
216
217 await sleep(150);
218 } catch (error: any) {
219 console.error(`[Clean] 无法移除对话 ${userId}:`, error.message);
220 if (error.message?.includes("FLOOD_WAIT")) {
221 await this.handleFloodWait(msg, error);
222 return;
223 }
224 }
225 }
226 }
227
228 // 构建结果反馈
229 let result = "";

Callers 1

handleDeletedCleanMethod · 0.95

Calls 6

editMessageMethod · 0.95
handleFloodWaitMethod · 0.95
handleErrorMethod · 0.95
errorMethod · 0.80
sleepFunction · 0.70
setMethod · 0.45

Tested by

no test coverage detected