koishi-plugin-chat-analyse 0.0.1 → 0.0.3
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/collector.d.ts +13 -8
- package/lib/index.js +29 -16
- package/package.json +1 -1
package/lib/collector.d.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import { Context } from 'koishi';
|
|
2
2
|
/**
|
|
3
3
|
* @file collector.ts
|
|
4
|
-
* @description
|
|
4
|
+
* @description 通过独立的事件监听器,分别持久化存储收到的普通消息和已确认的命令。
|
|
5
5
|
*/
|
|
6
6
|
declare module 'koishi' {
|
|
7
7
|
interface Tables {
|
|
8
|
-
|
|
8
|
+
analyse_origin_msg: {
|
|
9
9
|
id: number;
|
|
10
10
|
channelId: string;
|
|
11
11
|
userId: string;
|
|
12
12
|
content: string;
|
|
13
13
|
timestamp: Date;
|
|
14
14
|
};
|
|
15
|
+
analyse_origin_cmd: {
|
|
16
|
+
id: number;
|
|
17
|
+
channelId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
command: string;
|
|
20
|
+
content: string;
|
|
21
|
+
timestamp: Date;
|
|
22
|
+
};
|
|
15
23
|
}
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
18
|
-
* @class
|
|
19
|
-
* @description
|
|
26
|
+
* @class Collector
|
|
27
|
+
* @description 使用双监听器,精确捕获并存储消息和命令。
|
|
20
28
|
*/
|
|
21
|
-
export declare class
|
|
29
|
+
export declare class Collector {
|
|
22
30
|
private ctx;
|
|
23
|
-
/**
|
|
24
|
-
* @param ctx Koishi 的上下文对象,用于访问模型和事件系统
|
|
25
|
-
*/
|
|
26
31
|
constructor(ctx: Context);
|
|
27
32
|
}
|
package/lib/index.js
CHANGED
|
@@ -29,35 +29,48 @@ module.exports = __toCommonJS(src_exports);
|
|
|
29
29
|
var import_koishi = require("koishi");
|
|
30
30
|
|
|
31
31
|
// src/collector.ts
|
|
32
|
-
var
|
|
33
|
-
/**
|
|
34
|
-
* @param ctx Koishi 的上下文对象,用于访问模型和事件系统
|
|
35
|
-
*/
|
|
32
|
+
var Collector = class {
|
|
36
33
|
constructor(ctx) {
|
|
37
34
|
this.ctx = ctx;
|
|
38
|
-
ctx.model.extend("
|
|
35
|
+
ctx.model.extend("analyse_origin_msg", {
|
|
39
36
|
id: "unsigned",
|
|
40
37
|
channelId: "string",
|
|
41
38
|
userId: "string",
|
|
42
39
|
content: "text",
|
|
43
40
|
timestamp: "timestamp"
|
|
44
|
-
}, {
|
|
45
|
-
|
|
41
|
+
}, { autoInc: true });
|
|
42
|
+
ctx.model.extend("analyse_origin_cmd", {
|
|
43
|
+
id: "unsigned",
|
|
44
|
+
channelId: "string",
|
|
45
|
+
userId: "string",
|
|
46
|
+
command: "string",
|
|
47
|
+
content: "text",
|
|
48
|
+
timestamp: "timestamp"
|
|
49
|
+
}, { autoInc: true });
|
|
50
|
+
ctx.on("command/before-execute", async (argv) => {
|
|
51
|
+
await ctx.database.create("analyse_origin_cmd", {
|
|
52
|
+
channelId: argv.session.channelId,
|
|
53
|
+
userId: argv.session.userId,
|
|
54
|
+
command: argv.command.name,
|
|
55
|
+
content: argv.session.content,
|
|
56
|
+
timestamp: new Date(argv.session.timestamp)
|
|
57
|
+
});
|
|
46
58
|
});
|
|
47
59
|
ctx.on("message", async (session) => {
|
|
48
|
-
|
|
60
|
+
if (session.argv?.command) return;
|
|
61
|
+
const content = session.elements.map((element) => {
|
|
49
62
|
switch (element.type) {
|
|
50
63
|
case "text":
|
|
51
64
|
return element.attrs.content;
|
|
52
|
-
case "
|
|
53
|
-
return `[
|
|
65
|
+
case "img":
|
|
66
|
+
return element.attrs.summary === "[动画表情]" ? "[gif]" : `[${element.type}]`;
|
|
54
67
|
default:
|
|
55
|
-
return
|
|
68
|
+
return `[${element.type}]`;
|
|
56
69
|
}
|
|
57
|
-
});
|
|
58
|
-
const sanitizedContent =
|
|
70
|
+
}).join("");
|
|
71
|
+
const sanitizedContent = content.trim();
|
|
59
72
|
if (!sanitizedContent) return;
|
|
60
|
-
await ctx.database.create("
|
|
73
|
+
await ctx.database.create("analyse_origin_msg", {
|
|
61
74
|
channelId: session.channelId,
|
|
62
75
|
userId: session.userId,
|
|
63
76
|
content: sanitizedContent,
|
|
@@ -66,7 +79,7 @@ var MessageCollector = class {
|
|
|
66
79
|
});
|
|
67
80
|
}
|
|
68
81
|
static {
|
|
69
|
-
__name(this, "
|
|
82
|
+
__name(this, "Collector");
|
|
70
83
|
}
|
|
71
84
|
};
|
|
72
85
|
|
|
@@ -75,7 +88,7 @@ var name = "chat-analyse";
|
|
|
75
88
|
var Config = import_koishi.Schema.object({});
|
|
76
89
|
var using = ["database"];
|
|
77
90
|
function apply(ctx) {
|
|
78
|
-
new
|
|
91
|
+
new Collector(ctx);
|
|
79
92
|
}
|
|
80
93
|
__name(apply, "apply");
|
|
81
94
|
// Annotate the CommonJS export names for ESM import in node:
|