(client: any, msg: Api.Message, includeAll: boolean = false)
| 325 | |
| 326 | // 拉黑用户清理 |
| 327 | private async cleanBlockedPM(client: any, msg: Api.Message, includeAll: boolean = false): Promise<void> { |
| 328 | this.blockedCleanupStartTime = Date.now(); |
| 329 | |
| 330 | await this.editMessage(msg, |
| 331 | `🧹 开始清理拉黑用户\n\n模式: ${includeAll ? '全量清理' : '智能清理'}`); |
| 332 | |
| 333 | let offset = 0; |
| 334 | let success = 0, failed = 0, skipped = 0, totalUsers = 0, processedUsers = 0; |
| 335 | let consecutiveErrors = 0; |
| 336 | |
| 337 | // 获取总数 |
| 338 | try { |
| 339 | const initialBlocked = await client.invoke(new Api.contacts.GetBlocked({ offset: 0, limit: 1 })); |
| 340 | totalUsers = initialBlocked.className === 'contacts.BlockedSlice' |
| 341 | ? (initialBlocked as any).count || 0 |
| 342 | : (await client.invoke(new Api.contacts.GetBlocked({ offset: 0, limit: 1000 })))?.users?.length || 0; |
| 343 | } catch (error) { |
| 344 | console.error("获取用户总数失败:", error); |
| 345 | } |
| 346 | |
| 347 | while (true) { |
| 348 | try { |
| 349 | const blocked = await client.invoke(new Api.contacts.GetBlocked({ offset, limit: 100 })); |
| 350 | if (!blocked.users?.length) break; |
| 351 | |
| 352 | for (const user of blocked.users) { |
| 353 | processedUsers++; |
| 354 | |
| 355 | // 智能模式跳过机器人/诈骗账户 |
| 356 | if (!includeAll && (user.bot || user.scam || user.fake)) { |
| 357 | skipped++; |
| 358 | continue; |
| 359 | } |
| 360 | |
| 361 | try { |
| 362 | await client.invoke(new Api.contacts.Unblock({ id: user })); |
| 363 | success++; |
| 364 | |
| 365 | // 动态延迟 |
| 366 | const delay = this.getDynamicDelay(user, includeAll, consecutiveErrors); |
| 367 | await sleep(delay); |
| 368 | consecutiveErrors = 0; |
| 369 | } catch (error: any) { |
| 370 | if (error.message?.includes('FLOOD_WAIT_')) { |
| 371 | await this.handleFloodWait(msg, error); |
| 372 | continue; |
| 373 | } else { |
| 374 | failed++; |
| 375 | consecutiveErrors++; |
| 376 | await sleep(this.getDynamicDelay(user, includeAll, consecutiveErrors)); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | // 更新进度 |
| 381 | if (processedUsers % 10 === 0) { |
| 382 | await this.updateBlockedProgress(msg, processedUsers, totalUsers, success, failed, skipped, includeAll); |
| 383 | } |
| 384 | } |
no test coverage detected