koishi-plugin-chat-analyse 1.3.9 → 1.4.0

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/Data.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { Context, Command } from 'koishi';
2
+ /**
3
+ * @class Data
4
+ * @description 提供数据备份、恢复和清理等高级管理功能。
5
+ */
6
+ export declare class Data {
7
+ private ctx;
8
+ private config;
9
+ private dataDir;
10
+ constructor(ctx: Context, config: any);
11
+ /**
12
+ * @public
13
+ * @method registerCommands
14
+ * @description 在主命令下注册所有数据管理相关的子命令。
15
+ * @param cmd - 主命令实例。
16
+ */
17
+ registerCommands(cmd: Command): void;
18
+ }
package/lib/index.js CHANGED
@@ -1620,7 +1620,7 @@ var Renderer = class {
1620
1620
  const { title, time, list } = data;
1621
1621
  const CHUNK_SIZE = 100;
1622
1622
  const totalItems = list.length;
1623
- const countHeaderIndex = headers?.findIndex((h6) => ["总计发言", "条数", "次数", "数量"].includes(h6)) ?? -1;
1623
+ const countHeaderIndex = headers?.findIndex((h7) => ["总计发言", "条数", "次数", "数量"].includes(h7)) ?? -1;
1624
1624
  const totalCount = data.total || (countHeaderIndex > -1 ? list.reduce((sum, row) => sum + (Number(row[countHeaderIndex]) || 0), 0) : totalItems);
1625
1625
  const renderCell = /* @__PURE__ */ __name((cell, i) => {
1626
1626
  const headerText = headers?.[i] || "";
@@ -1668,7 +1668,7 @@ var Renderer = class {
1668
1668
  <thead>
1669
1669
  <tr>
1670
1670
  <th class="rank-cell">#</th>
1671
- ${headers.map((h6) => `<th>${h6}</th>`).join("")}
1671
+ ${headers.map((h7) => `<th>${h7}</th>`).join("")}
1672
1672
  </tr>
1673
1673
  </thead>` : ""}
1674
1674
  <tbody>
@@ -2106,8 +2106,9 @@ var path = __toESM(require("path"));
2106
2106
  var ALL_TABLES = ["analyse_user", "analyse_cmd", "analyse_msg", "analyse_rank", "analyse_at", "analyse_cache"];
2107
2107
  var BATCH_SIZE = 100;
2108
2108
  var Data = class {
2109
- constructor(ctx) {
2109
+ constructor(ctx, config) {
2110
2110
  this.ctx = ctx;
2111
+ this.config = config;
2111
2112
  this.dataDir = path.join(this.ctx.baseDir, "data", "chat-analyse");
2112
2113
  }
2113
2114
  static {
@@ -2173,7 +2174,7 @@ var Data = class {
2173
2174
  return "数据恢复失败";
2174
2175
  }
2175
2176
  });
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 }) => {
2177
+ 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
2178
  if (Object.keys(options).length === 0) return "请指定清除条件";
2178
2179
  if (options.table && !ALL_TABLES.includes(options.table)) return `表名 ${options.table} 无效`;
2179
2180
  try {
@@ -2183,6 +2184,14 @@ var Data = class {
2183
2184
  }
2184
2185
  const query = {};
2185
2186
  const descParts = [];
2187
+ let uidsToClear;
2188
+ if (options.limit > 0) {
2189
+ descParts.push(`发言数 < ${options.limit}`);
2190
+ const msgStats = await this.ctx.database.select("analyse_msg").groupBy("uid", { total: /* @__PURE__ */ __name((row) => import_koishi5.$.sum(row.count), "total") }).execute();
2191
+ const uidsFromLimit = msgStats.filter((s) => s.total < options.limit).map((s) => s.uid);
2192
+ if (uidsFromLimit.length === 0) return "未找到相关数据";
2193
+ uidsToClear = uidsFromLimit;
2194
+ }
2186
2195
  if (options.guild || options.user) {
2187
2196
  const userQuery = {};
2188
2197
  if (options.guild) {
@@ -2194,7 +2203,15 @@ var Data = class {
2194
2203
  userQuery.userId = userId;
2195
2204
  descParts.push(`用户 ${userId}`);
2196
2205
  }
2197
- const uidsToClear = (await this.ctx.database.get("analyse_user", userQuery)).map((u) => u.uid);
2206
+ const uidsFromScope = (await this.ctx.database.get("analyse_user", userQuery)).map((u) => u.uid);
2207
+ if (uidsToClear) {
2208
+ const scopeUidSet = new Set(uidsFromScope);
2209
+ uidsToClear = uidsToClear.filter((uid) => scopeUidSet.has(uid));
2210
+ } else {
2211
+ uidsToClear = uidsFromScope;
2212
+ }
2213
+ }
2214
+ if (uidsToClear) {
2198
2215
  if (uidsToClear.length === 0) return "未找到相关数据";
2199
2216
  query.uid = { $in: [...new Set(uidsToClear)] };
2200
2217
  }
@@ -2207,16 +2224,14 @@ var Data = class {
2207
2224
  descParts.push(`命令 ${options.command}`);
2208
2225
  }
2209
2226
  const tablesToClear = options.command ? ["analyse_cmd"] : options.table ? [options.table] : ALL_TABLES.filter((t) => t !== "analyse_user");
2210
- let foundData = false;
2227
+ let totalRemoved = 0;
2211
2228
  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
- }
2229
+ const tableQuery = { ...query };
2230
+ if (tableName !== "analyse_cmd" && tableQuery.command) continue;
2231
+ const result = await this.ctx.database.remove(tableName, tableQuery);
2232
+ totalRemoved += result.removed;
2217
2233
  }
2218
- if (!foundData) return "未找到相关数据";
2219
- for (const tableName of tablesToClear) await this.ctx.database.remove(tableName, query);
2234
+ if (totalRemoved === 0) return "未找到相关数据";
2220
2235
  const tableString = options.table ? `表 ${options.table}` : "所有表";
2221
2236
  const descString = descParts.join("、");
2222
2237
  if (descString) {
@@ -2229,6 +2244,48 @@ var Data = class {
2229
2244
  return "数据清理失败";
2230
2245
  }
2231
2246
  });
2247
+ if (this.config.enableOriRecord) {
2248
+ cmd.subcommand(".view <time:string>", "查询消息记录", { authority: 4 }).usage("查询指定时间点后的消息记录,默认查询当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").action(async ({ session, options }, time) => {
2249
+ if (!time) return '请以"YYYY-MM-DD HH:MM:SS"格式输入起始时间';
2250
+ const since = new Date(time);
2251
+ if (isNaN(since.getTime())) return "时间格式无效";
2252
+ try {
2253
+ const userQuery = {};
2254
+ if (!options.guild && !options.user) {
2255
+ if (!session.guildId) return "请指定查询范围";
2256
+ userQuery.channelId = session.guildId;
2257
+ } else {
2258
+ if (options.guild) userQuery.channelId = options.guild;
2259
+ if (options.user) userQuery.userId = import_koishi5.Element.select(options.user, "at")[0]?.attrs.id ?? options.user;
2260
+ }
2261
+ const usersInScope = await this.ctx.database.get("analyse_user", userQuery);
2262
+ if (usersInScope.length === 0) return "暂无用户数据";
2263
+ const uids = usersInScope.map((u) => u.uid);
2264
+ const records = await this.ctx.database.get("analyse_cache", {
2265
+ uid: { $in: uids },
2266
+ timestamp: { $gte: since }
2267
+ }, {
2268
+ sort: { timestamp: "asc" },
2269
+ limit: 100
2270
+ });
2271
+ if (records.length === 0) return "暂无统计数据";
2272
+ const recordUids = [...new Set(records.map((r) => r.uid))];
2273
+ const users = await this.ctx.database.get("analyse_user", { uid: { $in: recordUids } }, ["uid", "userName", "userId"]);
2274
+ const userInfoMap = new Map(users.map((u) => [u.uid, { name: u.userName, id: u.userId }]));
2275
+ const messageElements = records.map((record) => {
2276
+ const senderInfo = userInfoMap.get(record.uid) || { name: `UID ${record.uid}`, id: "unknown" };
2277
+ const timeStr = record.timestamp.toLocaleTimeString("zh-CN", { hour12: false });
2278
+ const author = (0, import_koishi5.h)("author", { id: senderInfo.id, name: senderInfo.name });
2279
+ const content = import_koishi5.h.text(`[${timeStr}] ${record.content}`);
2280
+ return (0, import_koishi5.h)("message", {}, [author, content]);
2281
+ });
2282
+ await session.send((0, import_koishi5.h)("message", { forward: true }, messageElements));
2283
+ } catch (error) {
2284
+ this.ctx.logger.error("查询消息记录失败:", error);
2285
+ return "查询消息记录失败";
2286
+ }
2287
+ });
2288
+ }
2232
2289
  cmd.subcommand(".list", "列出数据", { authority: 4 }).usage("列出数据库中的频道和命令列表。").action(async () => {
2233
2290
  const [allChannelInfo, commands] = await Promise.all([
2234
2291
  this.ctx.database.get("analyse_user", {}, ["channelId", "channelName"]),
@@ -2469,7 +2526,7 @@ function apply(ctx, config) {
2469
2526
  const analyse = ctx.command("analyse", "数据分析");
2470
2527
  new Stat(ctx, config).registerCommands(analyse);
2471
2528
  if (config.enableWhoAt) new WhoAt(ctx, config).registerCommand(analyse);
2472
- if (config.enableDataIO) new Data(ctx).registerCommands(analyse);
2529
+ if (config.enableDataIO) new Data(ctx, config).registerCommands(analyse);
2473
2530
  if (config.enableWordCloud || config.enableSimilarActivity) new Analyse(ctx, config).registerCommands(analyse);
2474
2531
  }
2475
2532
  __name(apply, "apply");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
- "description": "强大而全面的聊天数据分析,支持统计命令,发言,消息类型,活跃度,支持发言排行和生成词云",
4
- "version": "1.3.9",
3
+ "description": "强大而全面的聊天数据分析插件。支持多维度统计(命令、发言、消息类型、活跃度),可生成发言排行、词云图,并提供完善的数据管理。",
4
+ "version": "1.4.0",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],
package/readme.md CHANGED
@@ -2,33 +2,34 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/koishi-plugin-chat-analyse?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-chat-analyse)
4
4
 
5
- 强大而全面的聊天数据分析,支持统计命令,发言,消息类型,活跃度,支持发言排行和生成词云
5
+ 强大而全面的聊天数据分析插件。支持多维度统计(命令、发言、消息类型、活跃度),可生成发言排行、词云图,并提供完善的数据管理。
6
6
 
7
7
  ## ✨ 功能特性
8
8
 
9
- - **高效数据收集**:采用异步、高并发和缓存机制,在不影响机器人性能的前提下,精确高效地收集聊天数据。
10
- - **多维度统计分析**:
11
- - **命令统计** (`cmdstat`):追踪指令使用频率,了解用户最常用的功能,支持按次数或时间排序。
12
- - **发言统计** (`msgstat`):分析用户发言类型与数量,掌握核心用户群体,支持按条数或时间排序。
13
- - **发言排行** (`rankstat`):生成指定时间范围内的用户发言排行榜,发掘群聊中的“龙王”。
14
- - **活跃度分析** (`activity`):以小时或天为单位,生成直观的周期性活跃度图表,洞察社群活跃时段。
15
- - **高级文本分析**:
16
- - **词云生成** (`wordcloud`):基于聊天记录,利用 Jieba 分词生成热门话题词云图,快速了解近期热点。
17
- - **相似活跃分析** (`simiactive`): 分析指定时间内,找出与您作息模式最相似的群友,并通过对比图表直观展示。
18
- - **提及追踪** (`whoatme`):轻松查询谁在什么时候因为什么内容提及了您,不再错过重要信息。
19
- - **强大的数据管理**:
20
- - **备份与恢复** (`.backup`/`.restore`):一键备份所有统计数据至本地,并可随时恢复,保障数据安全。
21
- - **精确清理** (`.clear`):提供多维度的筛选条件(如按时间、用户、群组、命令),精确清理不再需要的数据。
22
- - **精美图表渲染**:借助 Puppeteer 服务,将复杂的统计数据渲染成美观、易读的图片,方便在聊天中分享。
23
- - **高度可配置**:所有功能模块均可独立开关,并可自定义数据保留时长等核心参数,以适应不同场景的需求。
9
+ **高效数据收集**:采用异步、高并发和缓存机制,在不影响机器人性能的前提下,精确高效地收集聊天数据。
10
+ **多维度统计分析**:
11
+ **命令统计** (`cmdstat`):追踪指令使用频率,了解用户最常用的功能,支持按次数或时间排序。
12
+ **发言统计** (`msgstat`):分析用户发言类型与数量,掌握核心用户群体,支持按条数或时间排序。
13
+ **发言排行** (`rankstat`):生成指定时间范围内的用户发言排行榜,发掘群聊中的“龙王”。
14
+ **活跃度分析** (`activity`):以小时或天为单位,生成直观的周期性活跃度图表,洞察社群活跃时段。
15
+ **高级文本分析**:
16
+ **词云生成** (`wordcloud`):基于聊天记录,利用 Jieba 分词生成热门话题词云图,快速了解近期热点。
17
+ **相似活跃分析** (`simiactive`): 分析指定时间内,找出与您作息模式最相似的群友,并通过对比图表直观展示。
18
+ **提及追踪** (`whoatme`):轻松查询谁在什么时候因为什么内容提及了您,不再错过重要信息。
19
+ **强大的数据管理**:
20
+ **备份与恢复** (`.backup`/`.restore`):一键备份所有统计数据至本地,并可随时恢复,保障数据安全。
21
+ **精确清理** (`.clear`):提供多维度的筛选条件(如按时间、用户、群组、发言数),精确清理不再需要的数据。
22
+ **记录查看** (`.view`): 可回溯查看指定时间点后的原始消息记录。
23
+ **精美图表渲染**:借助 Puppeteer 服务,将复杂的统计数据渲染成美观、易读的图片,方便在聊天中分享。
24
+ **高度可配置**:所有功能模块均可独立开关,并可自定义数据保留时长等核心参数,以适应不同场景的需求。
24
25
 
25
26
  ## ⚙️ 前置服务
26
27
 
27
28
  本插件依赖以下 Koishi 服务,请确保您已正确安装并启用了它们:
28
29
 
29
- - **`database`**:用于存储所有统计分析数据。
30
- - **`puppeteer`**:用于将统计结果渲染成图片。
31
- - **`cron`**:用于执行数据定时清理任务。
30
+ **`database`**:用于存储所有统计分析数据。
31
+ **`puppeteer`**:用于将统计结果渲染成图片。
32
+ **`cron`**:用于执行数据定时清理任务。
32
33
 
33
34
  ## 📝 使用说明
34
35
 
@@ -37,72 +38,94 @@
37
38
  ### 指令列表
38
39
 
39
40
  | 指令 | 别名 | 描述 | 选项 |
40
- | :--- | :--- | :--- | :--- |
41
+ | :--| :--| :--| :--|
41
42
  | `cmdstat` | 命令统计 | 查询命令使用情况,展示方式根据选项变化 | `-u`, `-g`, `-a`, `-p`, `-s` |
42
43
  | `msgstat` | 发言统计 | 查询用户发言统计,展示方式根据选项变化 | `-u`, `-g`, `-a`, `-t`, `-s` |
43
44
  | `rankstat` | 发言排行 | 查询指定时间内的发言排行 | `-u`, `-g`, `-a`, `-t`, `-n`, `-o` |
44
45
  | `activity` | 活跃统计 | 查询周期性活跃度图表 | `-u`, `-g`, `-a`, `-d`, `-n`, `-o` |
45
46
  | `wordcloud` | 生成词云 | 基于聊天记录生成词云图 | `-u`, `-g`, `-t` |
46
- | `simiactive`| 作息分析 | 分析并找出与您作息相似的群友 | `-n` |
47
+ | `simiactive`| 相似活跃分析 | 分析并找出与您作息相似的群友 | `-n`, `-p` |
47
48
  | `whoatme` | 谁提及我 | 查看最近谁提及了您 | (无) |
49
+ | `analyse.view <time>`| 查询记录 | (管理) 查询指定时间点后的消息记录 | `-u`, `-g` |
48
50
  | `analyse.list` | 列出数据 | (管理) 列出已记录的频道和命令 | (无) |
49
51
  | `analyse.backup` | 备份数据 | (管理) 将所有数据备份为本地 JSON 文件 | (无) |
50
52
  | `analyse.restore` | 恢复数据 | (管理) 从本地 JSON 文件恢复数据 | (无) |
51
- | `analyse.clear` | 清除数据 | (管理) 根据条件精确清理数据 | `-t`, `-g`, `-u`, `-d`, `-c`, `-a` |
53
+ | `analyse.clear` | 清除数据 | (管理) 根据条件精确清理数据 | `-t`, `-g`, `-u`, `-d`, `-c`, `-l`, `-a` |
52
54
 
53
55
  **通用选项说明:**
54
56
 
55
- - `-u, --user <user>`: 指定用户 (可使用 @ 或 userID)。
56
- - `-g, --guild <guild>`: 指定群组 (需使用群组ID)。
57
- - `-a, --all`: 查询全局数据。
57
+ `-u, --user <user>`: 指定用户 (可使用 @ 或 userID)。
58
+ `-g, --guild <guild>`: 指定群组 (需使用群组ID)。
59
+ `-a, --all`: 查询全局数据。
58
60
 
59
61
  ### 🔎 指令详解
60
62
 
61
63
  #### `cmdstat` (命令统计)
62
64
 
63
- - **`cmdstat`**: 查询**当前群组**所有用户的命令统计。
64
- - **`cmdstat -u @用户`**: 查询**指定用户**在**所有群组**的命令统计。
65
- - **`cmdstat -g <群组ID>`**: 查询**指定群组**所有用户的命令统计。
66
- - **`cmdstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的命令统计。
67
- - **`cmdstat -a`**: 查询**全局**(所有用户+所有群组)的命令统计。
68
- - **选项 `-p, --separate`**: 分离展示子命令,不合并到主命令。
69
- - **选项 `-s, --sortByTime`**: 按最后使用时间降序排序(默认按使用次数)。
65
+ **`cmdstat`**: 查询**当前群组**所有用户的命令统计。
66
+ **`cmdstat -u @用户`**: 查询**指定用户**在**所有群组**的命令统计。
67
+ **`cmdstat -g <群组ID>`**: 查询**指定群组**所有用户的命令统计。
68
+ **`cmdstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的命令统计。
69
+ **`cmdstat -a`**: 查询**全局**(所有用户+所有群组)的命令统计。
70
+ **选项 `-p, --separate`**: 分离展示子命令,不合并到主命令。
71
+ **选项 `-s, --sortByTime`**: 按最后使用时间降序排序(默认按使用次数)。
70
72
 
71
73
  #### `msgstat` (发言统计)
72
74
 
73
- - **`msgstat`**: 查询**当前群组**的发言统计 (按**用户**展示)。
74
- - **`msgstat -u @用户`**: 查询**指定用户**的发言统计 (按**群组**展示)。
75
- - **`msgstat -g <群组ID>`**: 查询**指定群组**的发言统计 (按**用户**展示)。
76
- - **`msgstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的发言统计 (按**消息类型**展示)。
77
- - **`msgstat -a`**: 查询**全局**发言统计 (按**用户**展示)。
78
- - **选项 `-t, --type <类型>`**: 筛选指定消息类型 (`text`, `face`, `image` 等),不改变上述展示逻辑。
79
- - **选项 `-s, --sortByTime`**: 按最后发言时间降序排序(默认按发言条数)。
75
+ **`msgstat`**: 查询**当前群组**的发言统计 (按**用户**展示)。
76
+ **`msgstat -u @用户`**: 查询**指定用户**的发言统计 (按**群组**展示)。
77
+ **`msgstat -g <群组ID>`**: 查询**指定群组**的发言统计 (按**用户**展示)。
78
+ **`msgstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的发言统计 (按**消息类型**展示)。
79
+ **`msgstat -a`**: 查询**全局**发言统计 (按**用户**展示)。
80
+ **选项 `-t, --type <类型>`**: 筛选指定消息类型 (`text`, `face`, `image` 等),不改变上述展示逻辑。
81
+ **选项 `-s, --sortByTime`**: 按最后发言时间降序排序(默认按发言条数)。
80
82
 
81
83
  #### `rankstat` (发言排行)
82
84
 
83
- - **`rankstat`**: 查询**当前群组**的发言排行 (按**用户**排名)。
84
- - **`rankstat -u @用户`**: 查询**指定用户**的发言排行 (按**群组**排名)。
85
- - **`rankstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的发言排行 (按**消息类型**排名)。
86
- - **`rankstat -a`**: 查询**全局**发言排行 (按**用户**排名)。
87
- - **选项 `-n, --duration <小时数>`**: 指定查询范围的时长,默认为 `24`。
88
- - **选项 `-o, --offset <小时数>`**: 指定查询结束时间的偏移量(从现在往前推的小时数),默认为 `0`。
89
- - **选项 `-t, --type <类型>`**: 筛选指定消息类型。
85
+ **`rankstat`**: 查询**当前群组**的发言排行 (按**用户**排名)。
86
+ **`rankstat -u @用户`**: 查询**指定用户**的发言排行 (按**群组**排名)。
87
+ **`rankstat -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的发言排行 (按**消息类型**排名)。
88
+ **`rankstat -a`**: 查询**全局**发言排行 (按**用户**排名)。
89
+ **选项 `-n, --duration <小时数>`**: 指定查询范围的时长,默认为 `24`。
90
+ **选项 `-o, --offset <小时数>`**: 指定查询结束时间的偏移量(从现在往前推的小时数),默认为 `0`。
91
+ **选项 `-t, --type <类型>`...**: 筛选指定消息类型。
90
92
 
91
93
  #### `activity` (活跃统计)
92
94
 
93
- - **`activity`**: 查询**当前群组**的活跃度。
94
- - **`activity -a`**: 查询**全局**活跃度。
95
- - **`activity -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的活跃度。
96
- - **选项 `-n, --duration <数值>`**: 指定查询范围的时长,默认为 `24`。
97
- - **选项 `-o, --offset <数值>`**: 指定查询结束时间的偏移量,默认为 `0`。
98
- - **选项 `-d, --days`**: 将 `-n` 和 `-o` 的单位从**小时**切换为**天**。
95
+ **`activity`**: 查询**当前群组**的活跃度。
96
+ **`activity -a`**: 查询**全局**活跃度。
97
+ **`activity -u @用户 -g <群组ID>`**: 查询**指定用户**在**指定群组**的活跃度。
98
+ **选项 `-n, --duration <数值>`**: 指定查询范围的时长,默认为 `24`。
99
+ **选项 `-o, --offset <数值>`**: 指定查询结束时间的偏移量,默认为 `0`。
100
+ **选项 `-d, --days`**: 将 `-n` 和 `-o` 的单位从**小时**切换为**天**。
101
+
102
+ #### `wordcloud` (生成词云)
103
+
104
+ **`wordcloud`**: 基于**当前群组**最近 `24` 小时聊天记录生成词云。
105
+ **选项 `-u, --user <user>`**: 指定用户。
106
+ **选项 `-g, --guild <guild>`**: 指定群组。
107
+ **选项 `-t, --hours <小时数>`**: 指定查询时长,默认为 `24`。
99
108
 
100
109
  #### `simiactive` (相似活跃分析)
101
110
 
102
- - **`simiactive`**: 在**当前群组**中,分析最近 **24 小时**内与您作息最相似的群友。
103
- - **`simiactive -n 48`**: 指定分析最近 **48 小时**的数据。
104
- - **选项 `-n, --hours <小时数>`**: 指定查询范围的时长,默认为 `24`。
105
- - **选项 `-p, --separate`**: 分离小时数据,不按天聚合进行分析。
111
+ **`simiactive`**: 在**当前群组**中,分析最近 **24 小时**内与您作息最相似的群友。
112
+ **`simiactive -n 48`**: 指定分析最近 **48 小时**的数据。
113
+ **选项 `-n, --hours <小时数>`**: 指定查询范围的时长,默认为 `24`。
114
+ **选项 `-p, --separate`**: 分离小时数据,不按天聚合进行分析。
115
+
116
+ #### `analyse.clear` (清除数据)
117
+
118
+ 该指令用于高级数据管理,请谨慎使用。
119
+
120
+ | 选项 | 别名 | 描述 |
121
+ | :--| :--| :--|
122
+ | `--table <表名>` | `-t` | 指定要清除的表名 (如 `analyse_cmd`)。若不指定,则默认清理除 `analyse_user` 外的所有表。 |
123
+ | `--guild <群组ID>` | `-g` | 仅清除指定群组的数据。 |
124
+ | `--user <用户>` | `-u` | 仅清除指定用户的数据。 |
125
+ | `--days <天数>` | `-d` | 清除指定天数之前的所有数据 (例如 `-d 30` 会删除30天前的数据)。 |
126
+ | `--command <命令>` | `-c` | 仅清除 `analyse_cmd` 表中指定的命令记录。 |
127
+ | `--limit <次数>` | `-l` | 清除总发言数小于指定次数的用户的所有记录。 |
128
+ | `--all` | `-a` | **【高危】** 清除插件产生的所有数据表,相当于重置插件。 |
106
129
 
107
130
  ## 🔧 配置项
108
131
 
@@ -110,25 +133,27 @@
110
133
 
111
134
  ### 杂项配置
112
135
 
113
- - `enableListener`: **启用消息监听**。总开关,关闭后插件将停止所有数据收集。 (默认: `true`)
114
- - `enableDataIO`: **启用数据管理**。控制 `.backup`, `.restore`, `.clear`, `.list` 等管理指令的可用性。 (默认: `true`)
136
+ `enableListener`: **启用消息监听**。总开关,关闭后插件将停止所有数据收集。 (默认: `true`)
137
+ `enableDataIO`: **启用数据管理**。控制 `.backup`, `.restore`, `.clear`, `.list`, `.view` 等管理指令的可用性。 (默认: `true`)
115
138
 
116
139
  ### 基础分析配置
117
140
 
118
- - `enableCmdStat`: **启用命令统计**。 (默认: `true`)
119
- - `enableMsgStat`: **启用消息统计**。 (默认: `true`)
120
- - `enableActivity`: **启用活跃统计**。 (默认: `true`)
121
- - `enableRankStat`: **启用发言排行**。 (默认: `true`)
122
- - `rankRetentionDays`: **排行保留天数**。发言排行数据的保留时长(天),`0` 为永久保留。 (默认: `180`)
123
- - `enableWhoAt`: **启用提及记录**。 (默认: `true`)
124
- - `atRetentionDays`: **提及保留天数**。`whoatme` 数据的保留时长(天),`0` 为永久保留。 (默认: `3`)
141
+ `enableCmdStat`: **启用命令统计**。 (默认: `true`)
142
+ `enableMsgStat`: **启用消息统计**。 (默认: `true`)
143
+ `enableActivity`: **启用活跃统计**。 (默认: `true`)
144
+ `enableRankStat`: **启用发言排行**。 (默认: `true`)
145
+ `rankRetentionDays`: **排行保留天数**。发言排行数据的保留时长(天),`0` 为永久保留。 (默认: `180`)
146
+ `enableWhoAt`: **启用提及记录**。 (默认: `true`)
147
+ `atRetentionDays`: **提及保留天数**。`whoatme` 数据的保留时长(天),`0` 为永久保留。 (默认: `3`)
125
148
 
126
149
  ### 高级分析配置
127
150
 
128
- - `enableOriRecord`: **启用原始记录**。是否记录原始消息内容以供词云等功能使用。 (默认: `true`)
129
- - `cacheRetentionDays`: **原始记录保留天数**。原始消息记录的保留时长(天),`0` 为永久保留。 (默认: `30`)
130
- - `enableWordCloud`: **启用词云生成** (依赖`原始记录`)。 (默认: `true`)
131
- - `enablesimiactive`: **启用相似活跃分析** (依赖`发言排行`或`活跃统计`)。 (默认: `true`)
151
+ `enableOriRecord`: **启用原始记录**。是否记录原始消息内容。这是 `.view` 和 `wordcloud` 功能的基础。 (默认: `true`)
152
+ `cacheRetentionDays`: **原始记录保留天数**。原始消息记录的保留时长(天),`0` 为永久保留。 (默认: `30`)
153
+ `enableWordCloud`: **启用词云生成**。
154
+ > **!** 此功能依赖 **`启用原始记录`**。 (默认: `true`)
155
+ `enableSimilarActivity`: **启用相似活跃分析**。
156
+ > **!** 此功能依赖 **`启用发言排行`** 或 **`启用活跃统计`**。 (默认: `true`)
132
157
 
133
158
  ## 📌 注意事项
134
159