koishi-plugin-chat-analyse 0.3.0 → 0.3.1
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/Stat.d.ts +5 -2
- package/lib/index.d.ts +2 -1
- package/lib/index.js +18 -12
- package/package.json +1 -1
package/lib/Stat.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class Stat {
|
|
|
17
17
|
constructor(ctx: Context, config: Config);
|
|
18
18
|
/**
|
|
19
19
|
* @method registerCommands
|
|
20
|
-
* @description 根据插件配置,动态地将 `.
|
|
20
|
+
* @description 根据插件配置,动态地将 `.cmd`, `.msg`, `.rank` 子命令注册到主 `analyse` 命令下。
|
|
21
21
|
* @param {Command} analyse - 主 `analyse` 命令实例。
|
|
22
22
|
*/
|
|
23
23
|
registerCommands(analyse: Command): void;
|
|
@@ -28,7 +28,10 @@ export declare class Stat {
|
|
|
28
28
|
* @description 通用的标题生成器。根据查询参数和类型选项动态生成易于理解的图片标题。
|
|
29
29
|
* @param {string} [guildId] - (可选) 查询的群组 ID。
|
|
30
30
|
* @param {string} [userId] - (可选) 查询的用户 ID。
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {object} options - 标题的配置选项。
|
|
32
|
+
* @param {'命令' | '消息' | '排行'} options.main - 标题主类型。
|
|
33
|
+
* @param {string} [options.subtype] - (可选) 消息类型的子类型。
|
|
34
|
+
* @param {number} [options.timeRange] - (可选) 排行的时间范围(小时)。
|
|
32
35
|
* @returns {Promise<string>} 生成的标题字符串。
|
|
33
36
|
*/
|
|
34
37
|
private generateTitle;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var Collector = class _Collector {
|
|
|
42
42
|
this.config = config;
|
|
43
43
|
this.defineModels();
|
|
44
44
|
ctx.on("message", (session) => this.handleMessage(session));
|
|
45
|
-
if (this.config.
|
|
45
|
+
if (this.config.enableOriRecord) {
|
|
46
46
|
this.flushInterval = setInterval(() => this.flushCacheBuffer(), _Collector.FLUSH_INTERVAL);
|
|
47
47
|
ctx.on("dispose", () => {
|
|
48
48
|
clearInterval(this.flushInterval);
|
|
@@ -90,7 +90,7 @@ var Collector = class _Collector {
|
|
|
90
90
|
count: "unsigned",
|
|
91
91
|
timestamp: "timestamp"
|
|
92
92
|
}, { primary: ["uid", "type", "hour"] });
|
|
93
|
-
if (this.config.
|
|
93
|
+
if (this.config.enableOriRecord) {
|
|
94
94
|
this.ctx.model.extend("analyse_cache", {
|
|
95
95
|
id: "unsigned",
|
|
96
96
|
uid: "unsigned",
|
|
@@ -133,7 +133,7 @@ var Collector = class _Collector {
|
|
|
133
133
|
timestamp: messageTime
|
|
134
134
|
}]);
|
|
135
135
|
}
|
|
136
|
-
if (this.config.
|
|
136
|
+
if (this.config.enableOriRecord) {
|
|
137
137
|
this.cacheBuffer.push({
|
|
138
138
|
uid,
|
|
139
139
|
content: this.sanitizeContent(elements),
|
|
@@ -360,12 +360,12 @@ var Stat = class {
|
|
|
360
360
|
renderer;
|
|
361
361
|
/**
|
|
362
362
|
* @method registerCommands
|
|
363
|
-
* @description 根据插件配置,动态地将 `.
|
|
363
|
+
* @description 根据插件配置,动态地将 `.cmd`, `.msg`, `.rank` 子命令注册到主 `analyse` 命令下。
|
|
364
364
|
* @param {Command} analyse - 主 `analyse` 命令实例。
|
|
365
365
|
*/
|
|
366
366
|
registerCommands(analyse) {
|
|
367
367
|
if (this.config.enableCmdStat) {
|
|
368
|
-
analyse.subcommand(".
|
|
368
|
+
analyse.subcommand(".cmd", "命令使用统计").option("user", "-u [user:user] 指定用户").option("guild", "-g [guildId:string] 指定群组").usage("查询用户或群组的命令使用统计,默认展示全局统计。").action(async ({ session, options }) => {
|
|
369
369
|
const userId = options.user ? import_koishi3.h.select(options.user, "user")[0]?.attrs.id : void 0;
|
|
370
370
|
let guildId = options.guild;
|
|
371
371
|
if (!userId && !guildId && session.guildId) {
|
|
@@ -393,7 +393,7 @@ var Stat = class {
|
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
395
|
if (this.config.enableMsgStat) {
|
|
396
|
-
analyse.subcommand(".
|
|
396
|
+
analyse.subcommand(".msg", "消息发送统计").option("user", "-u [user:user] 指定用户").option("guild", "-g [guildId:string] 指定群组").option("type", "-t <type:string> 指定类型").usage("查询用户或群组的消息发送统计,默认展示全局统计。").action(async ({ session, options }) => {
|
|
397
397
|
const userId = options.user ? import_koishi3.h.select(options.user, "user")[0]?.attrs.id : void 0;
|
|
398
398
|
let guildId = options.guild;
|
|
399
399
|
if (!userId && !guildId && !options.type && session.guildId) {
|
|
@@ -434,7 +434,9 @@ var Stat = class {
|
|
|
434
434
|
return "渲染消息统计图片失败";
|
|
435
435
|
}
|
|
436
436
|
});
|
|
437
|
-
|
|
437
|
+
}
|
|
438
|
+
if (this.config.enableRankStat) {
|
|
439
|
+
analyse.subcommand(".rank", "用户发言排行").option("guild", "-g [guildId:string] 指定群组").option("hours", "-h <hours:number> 指定时长", { fallback: 24 }).usage("查询用户或群组的用户发言排行,默认展示全局统计。").action(async ({ session, options }) => {
|
|
438
440
|
let guildId = options.guild;
|
|
439
441
|
if (!guildId && session.guildId) guildId = session.guildId;
|
|
440
442
|
if (!guildId) return "请指定查询范围";
|
|
@@ -470,7 +472,10 @@ var Stat = class {
|
|
|
470
472
|
* @description 通用的标题生成器。根据查询参数和类型选项动态生成易于理解的图片标题。
|
|
471
473
|
* @param {string} [guildId] - (可选) 查询的群组 ID。
|
|
472
474
|
* @param {string} [userId] - (可选) 查询的用户 ID。
|
|
473
|
-
* @param {
|
|
475
|
+
* @param {object} options - 标题的配置选项。
|
|
476
|
+
* @param {'命令' | '消息' | '排行'} options.main - 标题主类型。
|
|
477
|
+
* @param {string} [options.subtype] - (可选) 消息类型的子类型。
|
|
478
|
+
* @param {number} [options.timeRange] - (可选) 排行的时间范围(小时)。
|
|
474
479
|
* @returns {Promise<string>} 生成的标题字符串。
|
|
475
480
|
*/
|
|
476
481
|
async generateTitle(guildId, userId, options) {
|
|
@@ -635,13 +640,14 @@ var name = "chat-analyse";
|
|
|
635
640
|
var using = ["database", "puppeteer"];
|
|
636
641
|
var Config = import_koishi4.Schema.intersect([
|
|
637
642
|
import_koishi4.Schema.object({
|
|
638
|
-
enableListener: import_koishi4.Schema.boolean().default(true).description("
|
|
639
|
-
|
|
643
|
+
enableListener: import_koishi4.Schema.boolean().default(true).description("启用消息监听"),
|
|
644
|
+
enableOriRecord: import_koishi4.Schema.boolean().default(true).description("启用原始记录")
|
|
645
|
+
}).description("监听配置"),
|
|
640
646
|
import_koishi4.Schema.object({
|
|
641
647
|
enableCmdStat: import_koishi4.Schema.boolean().default(true).description("启用命令统计"),
|
|
642
648
|
enableMsgStat: import_koishi4.Schema.boolean().default(true).description("启用消息统计"),
|
|
643
|
-
|
|
644
|
-
}).description("
|
|
649
|
+
enableRankStat: import_koishi4.Schema.boolean().default(true).description("启用发言排行")
|
|
650
|
+
}).description("命令配置")
|
|
645
651
|
]);
|
|
646
652
|
function apply(ctx, config) {
|
|
647
653
|
if (config.enableListener) new Collector(ctx, config);
|