koishi-plugin-chat-analyse 0.4.9 → 0.4.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.
@@ -44,14 +44,14 @@ declare module 'koishi' {
44
44
  }
45
45
  /**
46
46
  * @class Collector
47
- * @description 核心数据收集器。根据插件配置,高效地监听、收集、缓冲并持久化聊天数据。
47
+ * @description 核心数据收集器。根据配置,高效地监听、收集、缓冲并持久化聊天数据。
48
48
  */
49
49
  export declare class Collector {
50
50
  private ctx;
51
51
  private config;
52
- /** @const {number} FLUSH_INTERVAL - 内存缓存区自动刷新到数据库的时间间隔。 */
52
+ /** @property FLUSH_INTERVAL - 内存缓存区定时刷入数据库的间隔(毫秒)。 */
53
53
  private static readonly FLUSH_INTERVAL;
54
- /** @const {number} BUFFER_THRESHOLD - 内存缓存区触发自动刷新的消息数量阈值。 */
54
+ /** @property BUFFER_THRESHOLD - 内存缓存区触发刷新的消息数量阈值。 */
55
55
  private static readonly BUFFER_THRESHOLD;
56
56
  private msgStatBuffer;
57
57
  private rankStatBuffer;
@@ -62,48 +62,26 @@ export declare class Collector {
62
62
  private pendingUserRequests;
63
63
  private flushInterval;
64
64
  /**
65
- * @constructor
66
- * @param {Context} ctx - Koishi 的插件上下文。
67
- * @param {Config} config - 插件的配置对象。
65
+ * @param ctx - Koishi 的插件上下文。
66
+ * @param config - 插件的配置对象。
68
67
  */
69
68
  constructor(ctx: Context, config: Config);
70
69
  /**
71
- * @private
72
- * @method defineModels
73
- * @description 定义插件所需的所有数据表模型。
70
+ * @private @method onMessage
71
+ * @description 统一的消息事件处理器,解析消息并更新各类统计数据的缓冲区。
72
+ * @param session - Koishi 的会话对象。
74
73
  */
75
- private defineModels;
74
+ private onMessage;
76
75
  /**
77
- * @private
78
- * @async
79
- * @method handleMessage
80
- * @description 统一的消息和命令处理器。它会解析收到的消息,提取关键信息并更新相应的统计数据。
81
- * @param {Session} session - Koishi 的会话对象,包含消息的全部信息。
82
- */
83
- private handleMessage;
84
- /**
85
- * @private
86
- * @async
87
- * @method getOrCreateCachedUser
88
- * @description 高效地获取或创建用户的中央记录,并全面利用缓存。
89
- * @param {Session} session - Koishi 会话对象,用于获取用户信息和 Bot 实例。
90
- * @param {string} channelId - 消息所在的频道或群组 ID。
91
- * @returns {Promise<UserCache | null>} 返回用户的缓存对象,如果操作失败则返回 `null`。
92
- */
93
- private getOrCreateCachedUser;
94
- /**
95
- * @private
96
- * @method sanitizeContent
97
- * @description 将 Koishi 的消息元素 (Element) 数组净化为纯文本字符串,以便存储和分析。
98
- * @param {Element[]} elements - 消息元素的数组。
99
- * @returns {string} 净化后的纯文本字符串。
76
+ * @private @method sanitizeContent
77
+ * @description 将 Koishi 消息元素数组净化为纯文本字符串。
78
+ * @param elements - 消息元素数组。
79
+ * @returns 净化后的纯文本。
100
80
  */
101
81
  private sanitizeContent;
102
82
  /**
103
- * @private
104
- * @async
105
- * @method flushBuffers
106
- * @description 将所有内存中的缓冲区数据批量写入数据库。
83
+ * @private @method flushBuffers
84
+ * @description 将所有内存中的数据缓冲区批量写入数据库,并清空缓冲区。
107
85
  */
108
86
  private flushBuffers;
109
87
  }
package/lib/Data.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import { Context, Command } from 'koishi';
2
2
  /**
3
3
  * @class Data
4
- * @description
5
- * 提供数据备份、恢复和清理的管理功能,恢复逻辑采用分批处理以优化性能。
6
- * 清理功能支持按表、时间范围和用户范围进行精确操作。
4
+ * @description 提供数据备份、恢复和清理等高级管理功能。恢复逻辑采用分批处理以优化性能。
7
5
  */
8
6
  export declare class Data {
9
7
  private ctx;
@@ -12,8 +10,8 @@ export declare class Data {
12
10
  /**
13
11
  * @public
14
12
  * @method registerCommands
15
- * @description 在 'analyse.admin' 命令下注册所有数据管理相关的子命令。
16
- * @param {Command} analyse - '.admin' 命令实例。
13
+ * @description 在 `analyse` 命令下注册所有数据管理相关的子命令 (`.backup`, `.restore`, `.clear`, `.list`)。
14
+ * @param analyse - `analyse` 命令实例。
17
15
  */
18
16
  registerCommands(analyse: Command): void;
19
17
  }
package/lib/Renderer.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import { Context } from 'koishi';
2
- /**
3
- * 定义了渲染列表中单行数据的格式。它是一个由字符串、数字或 `Date` 对象组成的数组。
4
- */
2
+ /** 定义了渲染列表中单行数据的格式,是一个由字符串、数字或 `Date` 对象构成的数组。 */
5
3
  export type RenderListItem = (string | number | Date)[];
6
4
  /**
7
5
  * @interface ListRenderData
8
- * @description 定义了调用 `renderList` 方法所需的数据结构。
9
- * 它包含了渲染一张完整列表图片所必需的所有信息。
6
+ * @description 定义了调用 `renderList` 方法所需的数据结构,包含了渲染一张完整列表图片所必需的所有信息。
10
7
  */
11
8
  export interface ListRenderData {
12
9
  title: string;
@@ -16,45 +13,37 @@ export interface ListRenderData {
16
13
  }
17
14
  /**
18
15
  * @class Renderer
19
- * @classdesc
20
- * 负责将结构化的数据(特别是列表)转换为设计精美的PNG图片。
21
- * 其核心特性是能够动态计算内容尺寸,生成布局紧凑、自适应的图片。
16
+ * @description 负责将结构化的列表数据渲染为设计精美的 PNG 图片。其核心特性是能够动态计算内容尺寸,生成布局紧凑、自适应的图片。
22
17
  */
23
18
  export declare class Renderer {
24
19
  private ctx;
25
20
  /**
26
- * @param {Context} ctx - Koishi 的插件上下文,用于访问核心服务如 `puppeteer` 和 `logger`。
21
+ * @param ctx - Koishi 的插件上下文,用于访问 `puppeteer` 等核心服务。
27
22
  */
28
23
  constructor(ctx: Context);
29
24
  /**
30
25
  * @private
31
26
  * @method htmlToImage
32
- * @description
33
- * 负责将任意HTML字符串转换为PNG图片Buffer。
34
- * @param {string} html - 要渲染的HTML主体内容(不包含 `<html>` 和 `<body>` 标签)。
35
- * @returns {Promise<Buffer>} 返回一个包含PNG图片数据的 Buffer 对象。
36
- * @throws {Error} 如果 Puppeteer 截图过程中发生错误,将抛出异常。
27
+ * @description 将 HTML 字符串转换为 PNG 图片 Buffer。
28
+ * @param html - 要渲染的 HTML 主体内容。
29
+ * @returns 返回一个包含 PNG 图片数据的 Buffer。
37
30
  */
38
31
  private htmlToImage;
39
32
  /**
40
33
  * @private
41
34
  * @method formatDate
42
- * @description
43
- * `Date` 对象格式化为人类友好的相对时间字符串。
44
- * @param {Date} date - 需要格式化的日期对象。
45
- * @returns {string} - 格式化后的时间字符串。
35
+ * @description 将 `Date` 对象格式化为易于理解的相对时间或绝对日期字符串。
36
+ * @param date - 需要格式化的日期对象。
37
+ * @returns 格式化后的时间字符串。
46
38
  */
47
39
  private formatDate;
48
40
  /**
49
41
  * @public
50
42
  * @method renderList
51
- * @description
52
- * 接收一个标准化的 `ListRenderData` 对象和可选的表头数组,
53
- * 然后构建一个包含标题、统计信息和数据表格的完整HTML卡片。
54
- * @param {ListRenderData} data - 包含渲染所需全部信息的对象。
55
- * @param {string[]} [headers] - (可选) 表格的表头字符串数组。如果提供,将渲染表头。
56
- * @returns {Promise<string | Buffer>}
57
- * 如果成功,返回包含PNG图片的 Buffer。如果输入的数据列表为空,则返回一个提示性字符串。
43
+ * @description 构建并渲染一个包含标题、统计信息和数据表格的 HTML 卡片为图片。
44
+ * @param data - 包含渲染所需全部信息的对象。
45
+ * @param headers - (可选) 表格的表头字符串数组。
46
+ * @returns 成功时返回包含 PNG 图片的 Buffer,若列表为空则返回提示字符串。
58
47
  */
59
48
  renderList(data: ListRenderData, headers?: string[]): Promise<string | Buffer>;
60
49
  }
package/lib/Stat.d.ts CHANGED
@@ -10,98 +10,28 @@ export declare class Stat {
10
10
  private config;
11
11
  renderer: Renderer;
12
12
  /**
13
- * @constructor
14
- * @param {Context} ctx - Koishi 的插件上下文。
15
- * @param {Config} config - 插件的配置对象。
13
+ * @param ctx - Koishi 的插件上下文。
14
+ * @param config - 插件的配置对象。
16
15
  */
17
16
  constructor(ctx: Context, config: Config);
18
17
  /**
19
- * @private
20
- * @method setupCleanupTask
21
- * @description 设置一个定时清理任务。
22
- * 此任务会根据配置中的 `rankRetentionDays` 定期删除过期的发言排行数据,以防止数据库膨胀。
23
- */
24
- private setupCleanupTask;
25
- /**
26
- * @public
27
- * @method registerCommands
28
- * @description 根据插件配置,动态地将 `.cmd`, `.msg`, `.rank` 子命令注册到主 `analyse` 命令下。
29
- * @param {Command} analyse - 主 `analyse` 命令实例。
18
+ * @public @method registerCommands
19
+ * @description 根据配置,动态地将 `.cmd`, `.msg`, `.rank` 子命令注册到主 `analyse` 命令下。
20
+ * @param analyse - 主 `analyse` 命令实例。
30
21
  */
31
22
  registerCommands(analyse: Command): void;
32
23
  /**
33
- * @private
34
- * @method parseQueryScope
35
- * @description 解析命令的选项,将其转换为统一的查询范围对象(userId guildId)。
36
- * @param {Session} session - 当前会话对象。
37
- * @param {QueryScopeOptions} options - 命令传入的选项。
38
- * @returns {QueryScopeResult} 包含 userId、guildId 或 error 信息的查询范围对象。
24
+ * @private @method parseQueryScope
25
+ * @description 解析命令选项,转换为包含 UIDs 和描述性信息的统一查询范围对象。
26
+ * @param session - 当前会话对象。
27
+ * @param options - 命令选项。
28
+ * @returns 包含 uids、错误或范围描述的查询范围对象。
39
29
  */
40
30
  private parseQueryScope;
41
31
  /**
42
- * @private
43
- * @async
44
- * @method getUidsInScope
45
- * @description 根据查询范围(guildId, userId)获取匹配用户的 UID 列表。
46
- * @param {string} [guildId] - (可选) 群组 ID。
47
- * @param {string} [userId] - (可选) 用户 ID。
48
- * @returns {Promise<{ uids?: number[], error?: string }>} 包含 UID 数组或错误信息的对象。
49
- */
50
- private getUidsInScope;
51
- /**
52
- * @private
53
- * @async
54
- * @method generateTitle
55
- * @description 通用的标题生成器。根据查询参数和类型选项动态生成易于理解的图片标题。
56
- * @param {string} [guildId] - (可选) 查询的群组 ID。
57
- * @param {string} [userId] - (可选) 查询的用户 ID。
58
- * @param {object} options - 标题的配置选项。
59
- * @param {'命令' | '消息' | '排行'} options.main - 标题主类型。
60
- * @param {string} [options.subtype] - (可选) 消息类型的子类型。
61
- * @param {number} [options.timeRange] - (可选) 排行的时间范围(小时)。
62
- * @returns {Promise<string>} 生成的标题字符串。
32
+ * @private @method generateTitle
33
+ * @description 根据查询范围和类型动态生成易于理解的图片标题。
34
+ * @returns 生成的标题字符串。
63
35
  */
64
36
  private generateTitle;
65
- /**
66
- * @private
67
- * @async
68
- * @method getCommandStats
69
- * @description 从数据库中获取并聚合命令使用统计数据。
70
- * @param {string} [guildId] - (可选) 若提供,则将范围限制在此群组。
71
- * @param {string} [userId] - (可选) 若提供,则将范围限制在此用户。
72
- * @returns {Promise<{ list: RenderListItem[], total: number } | string>} 返回一个包含列表和总数的对象,或在无数据时返回提示字符串。
73
- */
74
- private getCommandStats;
75
- /**
76
- * @private
77
- * @async
78
- * @method getUserMessageStats
79
- * @description 从数据库中获取并聚合每个用户的消息统计数据。
80
- * @param {string} [guildId] - (可选) 若提供,则将范围限制在此群组。
81
- * @param {string} [userId] - (可选) 若提供,则将范围限制在此用户。
82
- * @returns {Promise<{ list: RenderListItem[], total: number } | string>} 返回一个包含列表和总数的对象,或在无数据时返回提示字符串。
83
- */
84
- private getUserMessageStats;
85
- /**
86
- * @private
87
- * @async
88
- * @method getMessageStatsByType
89
- * @description 按指定消息类型,从数据库中获取并聚合用户排行数据。
90
- * @param {string} type - 要查询的消息类型。
91
- * @param {string} [guildId] - (可选) 若提供,则将范围限制在此群组。
92
- * @param {string} [userId] - (可选) 若提供,则将范围限制在此用户。
93
- * @returns {Promise<{ list: RenderListItem[], total: number } | string>} 返回一个包含列表和总数的对象,或在无数据时返回提示字符串。
94
- */
95
- private getMessageStatsByType;
96
- /**
97
- * @private
98
- * @async
99
- * @method getActiveUserStats
100
- * @description 从数据库中获取并聚合指定时间范围内的活跃用户排行数据。
101
- * @param {number} hours - 查询过去的小时数。
102
- * @param {string} [guildId] - (可选) 要查询的群组 ID。若不提供,则进行全局排行。
103
- * @param {string} [type] - (可选) 要筛选的消息类型。
104
- * @returns {Promise<{ list: RenderListItem[], total: number } | string>} 返回一个包含列表和总数的对象,或在无数据时返回提示字符串。
105
- */
106
- private getActiveUserStats;
107
37
  }
package/lib/WhoAt.d.ts CHANGED
@@ -2,33 +2,20 @@ import { Context, Command } from 'koishi';
2
2
  import { Config } from './index';
3
3
  /**
4
4
  * @class WhoAt
5
- * @description
6
- * 负责处理与“谁@我”相关的功能。
7
- * 该类会注册一个 'whoatme' 子命令,允许用户查询在何时被谁提及。
8
- * 查询结果将以合并转发的形式发送给用户。
9
- * 此外,该类还包含一个定时任务,用于定期清理数据库中旧的@记录。
5
+ * @description 负责处理“谁@我”相关功能,包括查询和定时清理。
10
6
  */
11
7
  export declare class WhoAt {
12
8
  private ctx;
13
9
  private config;
14
10
  /**
15
- * WhoAt 类的构造函数。
16
- * @param {Context} ctx - Koishi 的插件上下文,用于访问框架核心功能和数据库等服务。
17
- * @param {Config} config - 插件的配置对象,包含如记录保留天数等设置。
11
+ * @param ctx - Koishi 的插件上下文。
12
+ * @param config - 插件的配置对象。
18
13
  */
19
14
  constructor(ctx: Context, config: Config);
20
15
  /**
21
- * @private
22
- * @method setupCleanupTask
23
- * @description 设置一个定时清理任务。
24
- * 此任务会根据配置中的 `atRetentionDays` 定期删除过期的@记录,以防止数据库膨胀。
25
- */
26
- private setupCleanupTask;
27
- /**
28
- * @public
29
- * @method registerCommand
16
+ * @public @method registerCommand
30
17
  * @description 在主 `analyse` 命令下注册 `whoatme` 子命令。
31
- * @param {Command} analyse - 用户传入的主 `analyse` 命令实例,`whoatme` 将作为其子命令。
18
+ * @param analyse - `analyse` 命令实例。
32
19
  */
33
20
  registerCommand(analyse: Command): void;
34
21
  }
package/lib/index.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import { Context, Schema } from 'koishi';
2
- /**
3
- * @name 插件使用说明
4
- * @description 在 Koishi 控制台中显示的插件介绍和帮助信息。
5
- */
2
+ /** @name 插件使用说明 */
6
3
  export declare const usage = "\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #4a6ee0;\">\uD83D\uDCCC \u63D2\u4EF6\u8BF4\u660E</h2>\n <p>\uD83D\uDCD6 <strong>\u4F7F\u7528\u6587\u6863</strong>\uFF1A\u8BF7\u70B9\u51FB\u5DE6\u4E0A\u89D2\u7684 <strong>\u63D2\u4EF6\u4E3B\u9875</strong> \u67E5\u770B\u63D2\u4EF6\u4F7F\u7528\u6587\u6863</p>\n <p>\uD83D\uDD0D <strong>\u66F4\u591A\u63D2\u4EF6</strong>\uFF1A\u53EF\u8BBF\u95EE <a href=\"https://github.com/YisRime\" style=\"color:#4a6ee0;text-decoration:none;\">\u82E1\u6DDE\u7684 GitHub</a> \u67E5\u770B\u672C\u4EBA\u7684\u6240\u6709\u63D2\u4EF6</p>\n</div>\n<div style=\"border-radius: 10px; border: 1px solid #ddd; padding: 16px; margin-bottom: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1);\">\n <h2 style=\"margin-top: 0; color: #e0574a;\">\u2764\uFE0F \u652F\u6301\u4E0E\u53CD\u9988</h2>\n <p>\uD83C\uDF1F \u559C\u6B22\u8FD9\u4E2A\u63D2\u4EF6\uFF1F\u8BF7\u5728 <a href=\"https://github.com/YisRime\" style=\"color:#e0574a;text-decoration:none;\">GitHub</a> \u4E0A\u7ED9\u6211\u4E00\u4E2A Star\uFF01</p>\n <p>\uD83D\uDC1B \u9047\u5230\u95EE\u9898\uFF1F\u8BF7\u901A\u8FC7 <strong>Issues</strong> \u63D0\u4EA4\u53CD\u9988\uFF0C\u6216\u52A0\u5165 QQ \u7FA4 <a href=\"https://qm.qq.com/q/PdLMx9Jowq\" style=\"color:#e0574a;text-decoration:none;\"><strong>855571375</strong></a> \u8FDB\u884C\u4EA4\u6D41</p>\n</div>\n";
7
4
  export declare const name = "chat-analyse";
8
5
  export declare const using: string[];
@@ -21,15 +18,12 @@ export interface Config {
21
18
  atRetentionDays: number;
22
19
  rankRetentionDays: number;
23
20
  }
24
- /**
25
- * @const {Schema<Config>} Config
26
- * @description 使用 Koishi 的 `Schema` 来定义配置项的类型、默认值和在控制台中的交互界面。
27
- */
21
+ /** @description 插件的配置项定义,使用 Koishi Schema 构建。 */
28
22
  export declare const Config: Schema<Config>;
29
23
  /**
30
24
  * @function apply
31
- * @description Koishi 插件的主入口函数。
32
- * @param {Context} ctx - Koishi 的插件上下文,提供了访问核心 API 的能力。
33
- * @param {Config} config - 用户在 `koishi.config.js` 或控制台中配置的对象。
25
+ * @description Koishi 插件的主入口函数,负责初始化和注册所有功能模块。
26
+ * @param ctx - Koishi 的插件上下文。
27
+ * @param config - 用户配置对象。
34
28
  */
35
29
  export declare function apply(ctx: Context, config: Config): void;