(cacheData: CacheData)
| 89 | const timestamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15); |
| 90 | const reportFile = path.join(CACHE_DIR, `report_${cacheData.chat_id}_${cacheData.mode}_${cacheData.day}_${timestamp}.csv`); |
| 91 | const modeNames: { [key: string]: string } = { |
| 92 | "1": `未上线超过${cacheData.day}天`, |
| 93 | "2": `未发言超过${cacheData.day}天`, |
| 94 | "3": `发言少于${cacheData.day}条`, |
| 95 | "4": "已注销账户", |
| 96 | "5": "所有普通成员", |
| 97 | }; |
| 98 | const csvContent = [ |
| 99 | ["群组清理报告"], |
| 100 | ["群组名称", cacheData.chat_title], |
| 101 | ["群组ID", cacheData.chat_id.toString()], |
| 102 | ["清理条件", modeNames[cacheData.mode] || "未知"], |
| 103 | ["搜索时间", cacheData.search_time.slice(0, 19)], |
| 104 | ["符合条件用户数量", cacheData.total_found.toString()], |
| 105 | [], |
| 106 | ["用户ID", "用户名", "姓名", "最后上线时间", "是否注销"], |
| 107 | ]; |
| 108 | for (const user of cacheData.users) { |
| 109 | const fullName = `${user.first_name} ${user.last_name}`.trim(); |
| 110 | csvContent.push([ |
| 111 | user.id.toString(), |
| 112 | user.username, |
| 113 | fullName, |
| 114 | user.last_online || "未知", |
| 115 | user.is_deleted ? "是" : "否", |
| 116 | ]); |
| 117 | } |
| 118 | const csvString = csvContent.map((row) => row.join(",")).join("\n"); |
| 119 | try { |
| 120 | fs.writeFileSync(reportFile, "\ufeff" + csvString, "utf8"); |
| 121 | console.log(`Report generated: ${reportFile}`); |
| 122 | } catch (error) { |
| 123 | console.error('Failed to write report file:', error); |
| 124 | await sleep(1000); |
| 125 | fs.writeFileSync(reportFile, "\ufeff" + csvString, "utf8"); |
| 126 | } |
| 127 | return reportFile; |
| 128 | } |
| 129 | |
| 130 | async function generateFailedReport(failedUsers: FailedUserInfo[], chatTitle: string, chatId: number): Promise<string> { |
| 131 | await ensureDirectories(); |
| 132 | const timestamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15); |
| 133 | const reportFile = path.join(CACHE_DIR, `failed_${chatId}_${timestamp}.csv`); |
| 134 | const csvContent = [ |
| 135 | ["群组清理失败用户报告"], |
no test coverage detected