koishi-plugin-chat-analyse 0.0.2 → 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 +2 -5
- package/lib/index.js +22 -32
- package/package.json +1 -1
package/lib/collector.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
@@ -24,12 +24,9 @@ declare module 'koishi' {
|
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* @class Collector
|
|
27
|
-
* @description
|
|
27
|
+
* @description 使用双监听器,精确捕获并存储消息和命令。
|
|
28
28
|
*/
|
|
29
29
|
export declare class Collector {
|
|
30
30
|
private ctx;
|
|
31
|
-
/**
|
|
32
|
-
* @param ctx Koishi 的上下文对象,用于访问模型和事件系统
|
|
33
|
-
*/
|
|
34
31
|
constructor(ctx: Context);
|
|
35
32
|
}
|
package/lib/index.js
CHANGED
|
@@ -30,9 +30,6 @@ var import_koishi = require("koishi");
|
|
|
30
30
|
|
|
31
31
|
// src/collector.ts
|
|
32
32
|
var Collector = class {
|
|
33
|
-
/**
|
|
34
|
-
* @param ctx Koishi 的上下文对象,用于访问模型和事件系统
|
|
35
|
-
*/
|
|
36
33
|
constructor(ctx) {
|
|
37
34
|
this.ctx = ctx;
|
|
38
35
|
ctx.model.extend("analyse_origin_msg", {
|
|
@@ -41,9 +38,7 @@ var Collector = class {
|
|
|
41
38
|
userId: "string",
|
|
42
39
|
content: "text",
|
|
43
40
|
timestamp: "timestamp"
|
|
44
|
-
}, {
|
|
45
|
-
autoInc: true
|
|
46
|
-
});
|
|
41
|
+
}, { autoInc: true });
|
|
47
42
|
ctx.model.extend("analyse_origin_cmd", {
|
|
48
43
|
id: "unsigned",
|
|
49
44
|
channelId: "string",
|
|
@@ -51,11 +46,8 @@ var Collector = class {
|
|
|
51
46
|
command: "string",
|
|
52
47
|
content: "text",
|
|
53
48
|
timestamp: "timestamp"
|
|
54
|
-
}, {
|
|
55
|
-
autoInc: true
|
|
56
|
-
});
|
|
49
|
+
}, { autoInc: true });
|
|
57
50
|
ctx.on("command/before-execute", async (argv) => {
|
|
58
|
-
if (!argv.command) return;
|
|
59
51
|
await ctx.database.create("analyse_origin_cmd", {
|
|
60
52
|
channelId: argv.session.channelId,
|
|
61
53
|
userId: argv.session.userId,
|
|
@@ -64,28 +56,26 @@ var Collector = class {
|
|
|
64
56
|
timestamp: new Date(argv.session.timestamp)
|
|
65
57
|
});
|
|
66
58
|
});
|
|
67
|
-
ctx.on("message", (session) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
88
|
-
}, 0);
|
|
59
|
+
ctx.on("message", async (session) => {
|
|
60
|
+
if (session.argv?.command) return;
|
|
61
|
+
const content = session.elements.map((element) => {
|
|
62
|
+
switch (element.type) {
|
|
63
|
+
case "text":
|
|
64
|
+
return element.attrs.content;
|
|
65
|
+
case "img":
|
|
66
|
+
return element.attrs.summary === "[动画表情]" ? "[gif]" : `[${element.type}]`;
|
|
67
|
+
default:
|
|
68
|
+
return `[${element.type}]`;
|
|
69
|
+
}
|
|
70
|
+
}).join("");
|
|
71
|
+
const sanitizedContent = content.trim();
|
|
72
|
+
if (!sanitizedContent) return;
|
|
73
|
+
await ctx.database.create("analyse_origin_msg", {
|
|
74
|
+
channelId: session.channelId,
|
|
75
|
+
userId: session.userId,
|
|
76
|
+
content: sanitizedContent,
|
|
77
|
+
timestamp: new Date(session.timestamp)
|
|
78
|
+
});
|
|
89
79
|
});
|
|
90
80
|
}
|
|
91
81
|
static {
|