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
173 const deletedUsers: Array<{id: string, username?: string}> = [];
174
175 try {
176 const dialogsMain = await client.getDialogs({});
177 let dialogsArchived: any[] = [];
178 try {
179 dialogsArchived = await client.getDialogs({ folder: 1 });
180 } catch (error: any) {
181 console.error(`[Clean] 获取归档对话失败:`, error?.message || error);
182 }
183
184 const dialogByUserId = new Map<string, any>();
185 const dialogs = [...(dialogsMain || []), ...(dialogsArchived || [])];
186
187 for (const dialog of dialogs) {
188 if (dialog.isUser && dialog.entity instanceof Api.User && dialog.entity.deleted) {
189 const user = dialog.entity;
190 const userId = user.id.toString();
191
192 if (!dialogByUserId.has(userId)) {
193 dialogByUserId.set(userId, dialog);
194 deletedUsers.push({
195 id: userId,
196 username: user.username || "已注销账号"
197 });
198 }
199 }
200 }
201
202 if (deleteDialogs) {
203 for (const [userId, dialog] of dialogByUserId.entries()) {
204 try {
205 /**
206 * 本 fork 的 teleproto 没有 client.deleteDialog,TL 层也没有
207 * messages.deleteDialog / just_remove;改用 messages.deleteHistory
208 * 清空本地历史,会话随之从列表移除。
209 * 不传 revoke:已注销账号无对端可撤销,开启反而可能失败。
210 */
211 await client.invoke(
212 new Api.messages.DeleteHistory({
213 peer: dialog.inputEntity,
214 maxId: 2147483647,
215 })
216 );
217
218 await sleep(150);
219 } catch (error: any) {
220 console.error(`[Clean] 无法移除对话 ${userId}:`, error.message);
221 if (error.message?.includes("FLOOD_WAIT")) {
222 await this.handleFloodWait(msg, error);
223 return;
224 }
225 }
226 }
227 }
228
229 // 构建结果反馈

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