koishi-plugin-chat-analyse 1.3.8 → 1.3.10

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.
Files changed (3) hide show
  1. package/lib/index.js +25 -11
  2. package/package.json +1 -1
  3. package/readme.md +4 -4
package/lib/index.js CHANGED
@@ -1700,7 +1700,7 @@ var Renderer = class {
1700
1700
  const shuffledColors = [...selectedPalette].sort(() => 0.5 - Math.random());
1701
1701
  const seriesColors = series.map((_, index) => shuffledColors[index % shuffledColors.length]);
1702
1702
  const width = 600, height = 320;
1703
- const padding = { top: 10, right: 15, bottom: 60, left: 25 };
1703
+ const padding = { top: 10, right: 20, bottom: 70, left: 20 };
1704
1704
  const chartWidth = width - padding.left - padding.right;
1705
1705
  const chartHeight = height - padding.top - padding.bottom;
1706
1706
  const maxVal = Math.max(1, ...series.flatMap((s) => s.data));
@@ -2173,7 +2173,7 @@ var Data = class {
2173
2173
  return "数据恢复失败";
2174
2174
  }
2175
2175
  });
2176
- cmd.subcommand(".clear", "清除数据", { authority: 4 }).usage(`清除指定统计数据,可精确控制清除范围。`).option("table", "-t <table:string> 指定表名").option("guild", "-g <guildId:string> 指定群组").option("user", "-u <user:string> 指定用户").option("days", "-d <days:number> 指定天数").option("command", "-c <command:string> 指定命令").option("all", "-a 全部清除").action(async ({ options }) => {
2176
+ cmd.subcommand(".clear", "清除数据", { authority: 4 }).usage(`清除指定统计数据,可精确控制清除范围。`).option("table", "-t <table:string> 指定表名").option("guild", "-g <guildId:string> 指定群组").option("user", "-u <user:string> 指定用户").option("days", "-d <days:number> 指定天数").option("command", "-c <command:string> 指定命令").option("limit", "-l <count:number> 指定次数").option("all", "-a 全部清除").action(async ({ options }) => {
2177
2177
  if (Object.keys(options).length === 0) return "请指定清除条件";
2178
2178
  if (options.table && !ALL_TABLES.includes(options.table)) return `表名 ${options.table} 无效`;
2179
2179
  try {
@@ -2183,6 +2183,14 @@ var Data = class {
2183
2183
  }
2184
2184
  const query = {};
2185
2185
  const descParts = [];
2186
+ let uidsToClear;
2187
+ if (options.limit > 0) {
2188
+ descParts.push(`发言数 < ${options.limit}`);
2189
+ const msgStats = await this.ctx.database.select("analyse_msg").groupBy("uid", { total: /* @__PURE__ */ __name((row) => import_koishi5.$.sum(row.count), "total") }).execute();
2190
+ const uidsFromLimit = msgStats.filter((s) => s.total < options.limit).map((s) => s.uid);
2191
+ if (uidsFromLimit.length === 0) return "未找到相关数据";
2192
+ uidsToClear = uidsFromLimit;
2193
+ }
2186
2194
  if (options.guild || options.user) {
2187
2195
  const userQuery = {};
2188
2196
  if (options.guild) {
@@ -2194,7 +2202,15 @@ var Data = class {
2194
2202
  userQuery.userId = userId;
2195
2203
  descParts.push(`用户 ${userId}`);
2196
2204
  }
2197
- const uidsToClear = (await this.ctx.database.get("analyse_user", userQuery)).map((u) => u.uid);
2205
+ const uidsFromScope = (await this.ctx.database.get("analyse_user", userQuery)).map((u) => u.uid);
2206
+ if (uidsToClear) {
2207
+ const scopeUidSet = new Set(uidsFromScope);
2208
+ uidsToClear = uidsToClear.filter((uid) => scopeUidSet.has(uid));
2209
+ } else {
2210
+ uidsToClear = uidsFromScope;
2211
+ }
2212
+ }
2213
+ if (uidsToClear) {
2198
2214
  if (uidsToClear.length === 0) return "未找到相关数据";
2199
2215
  query.uid = { $in: [...new Set(uidsToClear)] };
2200
2216
  }
@@ -2207,16 +2223,14 @@ var Data = class {
2207
2223
  descParts.push(`命令 ${options.command}`);
2208
2224
  }
2209
2225
  const tablesToClear = options.command ? ["analyse_cmd"] : options.table ? [options.table] : ALL_TABLES.filter((t) => t !== "analyse_user");
2210
- let foundData = false;
2226
+ let totalRemoved = 0;
2211
2227
  for (const tableName of tablesToClear) {
2212
- const records = await this.ctx.database.get(tableName, query, ["uid"]);
2213
- if (records.length > 0) {
2214
- foundData = true;
2215
- break;
2216
- }
2228
+ const tableQuery = { ...query };
2229
+ if (tableName !== "analyse_cmd" && tableQuery.command) continue;
2230
+ const result = await this.ctx.database.remove(tableName, tableQuery);
2231
+ totalRemoved += result.removed;
2217
2232
  }
2218
- if (!foundData) return "未找到相关数据";
2219
- for (const tableName of tablesToClear) await this.ctx.database.remove(tableName, query);
2233
+ if (totalRemoved === 0) return "未找到相关数据";
2220
2234
  const tableString = options.table ? `表 ${options.table}` : "所有表";
2221
2235
  const descString = descParts.join("、");
2222
2236
  if (descString) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "强大而全面的聊天数据分析,支持统计命令,发言,消息类型,活跃度,支持发言排行和生成词云",
4
- "version": "1.3.8",
4
+ "version": "1.3.10",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],
package/readme.md CHANGED
@@ -18,7 +18,7 @@
18
18
  - **提及追踪** (`whoatme`):轻松查询谁在什么时候因为什么内容提及了您,不再错过重要信息。
19
19
  - **强大的数据管理**:
20
20
  - **备份与恢复** (`.backup`/`.restore`):一键备份所有统计数据至本地,并可随时恢复,保障数据安全。
21
- - **精确清理** (`.clear`):提供多维度的筛选条件(如按时间、用户、群组、命令),精确清理不再需要的数据。
21
+ - **精确清理** (`.clear`):提供多维度的筛选条件(如按时间、用户、群组、发言数),精确清理不再需要的数据。
22
22
  - **精美图表渲染**:借助 Puppeteer 服务,将复杂的统计数据渲染成美观、易读的图片,方便在聊天中分享。
23
23
  - **高度可配置**:所有功能模块均可独立开关,并可自定义数据保留时长等核心参数,以适应不同场景的需求。
24
24
 
@@ -43,12 +43,12 @@
43
43
  | `rankstat` | 发言排行 | 查询指定时间内的发言排行 | `-u`, `-g`, `-a`, `-t`, `-n`, `-o` |
44
44
  | `activity` | 活跃统计 | 查询周期性活跃度图表 | `-u`, `-g`, `-a`, `-d`, `-n`, `-o` |
45
45
  | `wordcloud` | 生成词云 | 基于聊天记录生成词云图 | `-u`, `-g`, `-t` |
46
- | `simiactive`| 作息分析 | 分析并找出与您作息相似的群友 | `-n` |
46
+ | `simiactive`| 相似活跃分析 | 分析并找出与您作息相似的群友 | `-n`, `-p` |
47
47
  | `whoatme` | 谁提及我 | 查看最近谁提及了您 | (无) |
48
48
  | `analyse.list` | 列出数据 | (管理) 列出已记录的频道和命令 | (无) |
49
49
  | `analyse.backup` | 备份数据 | (管理) 将所有数据备份为本地 JSON 文件 | (无) |
50
50
  | `analyse.restore` | 恢复数据 | (管理) 从本地 JSON 文件恢复数据 | (无) |
51
- | `analyse.clear` | 清除数据 | (管理) 根据条件精确清理数据 | `-t`, `-g`, `-u`, `-d`, `-c`, `-a` |
51
+ | `analyse.clear` | 清除数据 | (管理) 根据条件精确清理数据 | `-t`, `-g`, `-u`, `-d`, `-c`, `-l`, `-a` |
52
52
 
53
53
  **通用选项说明:**
54
54
 
@@ -128,7 +128,7 @@
128
128
  - `enableOriRecord`: **启用原始记录**。是否记录原始消息内容以供词云等功能使用。 (默认: `true`)
129
129
  - `cacheRetentionDays`: **原始记录保留天数**。原始消息记录的保留时长(天),`0` 为永久保留。 (默认: `30`)
130
130
  - `enableWordCloud`: **启用词云生成** (依赖`原始记录`)。 (默认: `true`)
131
- - `enablesimiactive`: **启用相似活跃分析** (依赖`发言排行`或`活跃统计`)。 (默认: `true`)
131
+ - `enableSimilarActivity`: **启用相似活跃分析** (依赖`发言排行`或`活跃统计`)。 (默认: `true`)
132
132
 
133
133
  ## 📌 注意事项
134
134