()
| 303 | |
| 304 | if (exitMsgs.length === 0) { |
| 305 | console.log(`[autodelcmd] 没有未完成的删除任务`); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | console.log(`[autodelcmd] 检测到 ${exitMsgs.length} 个未完成的删除任务`); |
| 310 | |
| 311 | // 处理每个待删除的消息 |
| 312 | for (const exitMsg of exitMsgs) { |
| 313 | try { |
| 314 | try { |
| 315 | await this.client.getEntity(exitMsg.cid); |
| 316 | } catch (e) { |
| 317 | console.error(`[autodelcmd] 解析聊天实体失败:`, e); |
| 318 | } |
| 319 | |
| 320 | const message = await safeGetMessages(this.client, exitMsg.cid, { ids: [exitMsg.mid] }); |
| 321 | if (message && message[0]) { |
| 322 | console.log(`[autodelcmd] 找到消息 ID ${exitMsg.mid},将在10秒后删除`); |
| 323 | |
| 324 | // 使用较短的延迟时间完成未完成的删除任务 |
| 325 | this.scheduleTimeout(async () => { |
| 326 | try { |
| 327 | console.log(`[autodelcmd] 正在执行未完成的删除任务,消息 ID ${exitMsg.mid}`); |
| 328 | await message[0].delete({ revoke: true }); |
| 329 | } catch (error: any) { |
| 330 | console.error(`[autodelcmd] 删除消息 ID ${exitMsg.mid} 失败:`, error.message); |
| 331 | } |
| 332 | }, 10 * 1000); |
| 333 | } else { |
| 334 | console.log(`[autodelcmd] 未找到消息 ID ${exitMsg.mid},可能已被删除`); |
| 335 | } |
| 336 | } catch (error) { |
| 337 | console.error(`[autodelcmd] 处理消息 ${exitMsg.mid} 时出错:`, error); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // 清除已处理的退出消息记录 |
| 342 | await this.clearExitMessages(); |
| 343 | } |
| 344 | |
| 345 | private getChatId(msg: Api.Message): number | null { |
| 346 | const chatId = msg.chatId || (msg.peerId && typeof msg.peerId === 'object' && 'userId' in msg.peerId ? msg.peerId.userId : null); |
| 347 | return chatId ? Number(chatId) : null; |
| 348 | } |
| 349 | |
| 350 | private async delayDelete(msg: Api.Message, seconds: number) { |
no test coverage detected