koishi-plugin-chat-analyse 1.6.5 → 1.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +24 -18
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1784,7 +1784,7 @@ var Renderer = class {
|
|
|
1784
1784
|
const relativeSize = relativeFontSizes[i];
|
|
1785
1785
|
estimatedCurrentArea += Math.pow(relativeSize, 2) * wordText.length * 0.6;
|
|
1786
1786
|
}
|
|
1787
|
-
const scalingFactor = Math.sqrt(600 * 600 * 0.
|
|
1787
|
+
const scalingFactor = Math.sqrt(600 * 600 * 0.9 / Math.max(1, estimatedCurrentArea));
|
|
1788
1788
|
const wordList = words.map((word, i) => {
|
|
1789
1789
|
let finalSize = relativeFontSizes[i] * scalingFactor;
|
|
1790
1790
|
finalSize = Math.max(4, Math.min(128, finalSize));
|
|
@@ -1814,7 +1814,6 @@ var Renderer = class {
|
|
|
1814
1814
|
list: ${JSON.stringify(wordList)},
|
|
1815
1815
|
weightFactor: (size) => size,
|
|
1816
1816
|
backgroundColor: 'transparent',
|
|
1817
|
-
drawOutOfBound: true,
|
|
1818
1817
|
clearCanvas: false,
|
|
1819
1818
|
shrinkToFit: true,
|
|
1820
1819
|
rotateRatio: 1,
|
|
@@ -2133,7 +2132,7 @@ var Data = class {
|
|
|
2133
2132
|
this.ctx = ctx;
|
|
2134
2133
|
this.config = config;
|
|
2135
2134
|
this.dataDir = path.join(this.ctx.baseDir, "data", "chat-analyse");
|
|
2136
|
-
if (this.config.enableAutoBackup) this.ctx.cron("0
|
|
2135
|
+
if (this.config.enableAutoBackup) this.ctx.cron("0 1 1 * *", () => {
|
|
2137
2136
|
this.backupCache();
|
|
2138
2137
|
});
|
|
2139
2138
|
}
|
|
@@ -2149,24 +2148,31 @@ var Data = class {
|
|
|
2149
2148
|
async backupCache() {
|
|
2150
2149
|
try {
|
|
2151
2150
|
await fs.mkdir(this.dataDir, { recursive: true });
|
|
2152
|
-
const now = /* @__PURE__ */ new Date();
|
|
2153
|
-
const lastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
2154
|
-
const year = lastMonth.getFullYear();
|
|
2155
|
-
const month = (lastMonth.getMonth() + 1).toString().padStart(2, "0");
|
|
2156
|
-
const filename = `analyse_cache_${year}-${month}.json`;
|
|
2157
|
-
const filepath = path.join(this.dataDir, filename);
|
|
2158
2151
|
const allUsers = await this.ctx.database.get("analyse_user", {});
|
|
2159
2152
|
if (allUsers.length === 0) return;
|
|
2160
2153
|
const uidToUserInfoMap = new Map(allUsers.map((u) => [u.uid, u]));
|
|
2161
|
-
const
|
|
2162
|
-
|
|
2163
|
-
const
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2154
|
+
const now = /* @__PURE__ */ new Date();
|
|
2155
|
+
const lastMonthDate = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
2156
|
+
const year = lastMonthDate.getFullYear();
|
|
2157
|
+
const monthIndex = lastMonthDate.getMonth();
|
|
2158
|
+
const monthString = (monthIndex + 1).toString().padStart(2, "0");
|
|
2159
|
+
const daysInMonth = new Date(year, monthIndex + 1, 0).getDate();
|
|
2160
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
2161
|
+
const dayString = day.toString().padStart(2, "0");
|
|
2162
|
+
const filename = `analyse_cache_${year}-${monthString}-${dayString}.json`;
|
|
2163
|
+
const filepath = path.join(this.dataDir, filename);
|
|
2164
|
+
const startDate = new Date(year, monthIndex, day);
|
|
2165
|
+
const endDate = new Date(year, monthIndex, day + 1);
|
|
2166
|
+
const records = await this.ctx.database.get("analyse_cache", { timestamp: { $gte: startDate, $lt: endDate } });
|
|
2167
|
+
if (records.length === 0) continue;
|
|
2168
|
+
const dataToExport = records.map((record) => {
|
|
2169
|
+
const userInfo = uidToUserInfoMap.get(record.uid);
|
|
2170
|
+
if (!userInfo) return null;
|
|
2171
|
+
const { id, uid, ...restOfRecord } = record;
|
|
2172
|
+
return { userId: userInfo.userId, channelId: userInfo.channelId, ...restOfRecord };
|
|
2173
|
+
}).filter(Boolean);
|
|
2174
|
+
await fs.writeFile(filepath, JSON.stringify(dataToExport, null, 2));
|
|
2175
|
+
}
|
|
2170
2176
|
} catch (error) {
|
|
2171
2177
|
this.ctx.logger.error("原始记录备份失败:", error);
|
|
2172
2178
|
}
|