koishi-plugin-chat-analyse 1.7.6 → 1.7.8
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/Analyse.d.ts +1 -1
- package/lib/index.js +7 -6
- package/package.json +2 -2
package/lib/Analyse.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -2417,8 +2417,7 @@ ${commandOutput}`;
|
|
|
2417
2417
|
|
|
2418
2418
|
// src/Analyse.ts
|
|
2419
2419
|
var import_koishi6 = require("koishi");
|
|
2420
|
-
var
|
|
2421
|
-
var import_dict = require("@node-rs/jieba/dict");
|
|
2420
|
+
var import_segmentit = require("segmentit");
|
|
2422
2421
|
function cosineSimilarity(vecA, vecB) {
|
|
2423
2422
|
let dotProduct = 0;
|
|
2424
2423
|
let magA = 0;
|
|
@@ -2439,7 +2438,9 @@ var Analyse = class {
|
|
|
2439
2438
|
this.ctx = ctx;
|
|
2440
2439
|
this.config = config;
|
|
2441
2440
|
this.renderer = new Renderer(ctx);
|
|
2442
|
-
if (config.enableWordCloud)
|
|
2441
|
+
if (config.enableWordCloud) {
|
|
2442
|
+
this.segmentit = (0, import_segmentit.useDefault)(new import_segmentit.Segment());
|
|
2443
|
+
}
|
|
2443
2444
|
if (this.config.enableOriRecord && this.config.cacheRetentionDays > 0) {
|
|
2444
2445
|
this.ctx.cron("0 0 * * *", async () => {
|
|
2445
2446
|
const cutoffDate = new Date(Date.now() - this.config.cacheRetentionDays * import_koishi6.Time.day);
|
|
@@ -2451,7 +2452,7 @@ var Analyse = class {
|
|
|
2451
2452
|
__name(this, "Analyse");
|
|
2452
2453
|
}
|
|
2453
2454
|
renderer;
|
|
2454
|
-
|
|
2455
|
+
segmentit = null;
|
|
2455
2456
|
/**
|
|
2456
2457
|
* @public @method registerCommands
|
|
2457
2458
|
* @description 在主命令下注册子命令。
|
|
@@ -2461,7 +2462,7 @@ var Analyse = class {
|
|
|
2461
2462
|
if (this.config.enableWordCloud) {
|
|
2462
2463
|
cmd.subcommand("wordcloud", "生成词云").usage("基于聊天记录生成词云图,可指定范围,默认当前群组。").option("guild", "-g <guildId:string> 指定群组").option("user", "-u <user:string> 指定用户").option("hours", "-t <hours:number> 指定时长", { fallback: 24 }).action(async ({ session, options }) => {
|
|
2463
2464
|
try {
|
|
2464
|
-
if (!this.
|
|
2465
|
+
if (!this.segmentit) return "分词服务未就绪";
|
|
2465
2466
|
const scope = await parseQueryScope(this.ctx, session, options);
|
|
2466
2467
|
if (scope.error) return scope.error;
|
|
2467
2468
|
scope.uids ??= (await this.ctx.database.get("analyse_user", {}, ["uid"])).map((u) => u.uid);
|
|
@@ -2472,7 +2473,7 @@ var Analyse = class {
|
|
|
2472
2473
|
const excludeWords = new Set(this.config.excludeWords.split(",").map((w) => w.trim().toLowerCase()).filter(Boolean));
|
|
2473
2474
|
const exclusionRegex = /\[(face|file|forward|img|gif|audio|video|json|rps|markdown|dice|at:.*?)\]/g;
|
|
2474
2475
|
const allText = records.map((r) => r.content.replace(exclusionRegex, "")).join(" ");
|
|
2475
|
-
const words = this.
|
|
2476
|
+
const words = this.segmentit.doSegment(allText).map((res) => String(res.w)).filter((w) => {
|
|
2476
2477
|
const trimmedWord = w.trim();
|
|
2477
2478
|
if (trimmedWord.length <= 1) return false;
|
|
2478
2479
|
if (/^\d+$/.test(trimmedWord)) return false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chat-analyse",
|
|
3
3
|
"description": "强大而全面的聊天数据分析插件。支持多维度统计(命令、发言、消息类型、活跃度),可生成发言排行、词云图,并提供完善的数据管理和 AI 分析功能。",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.8",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Yis_Rime <yis_rime@outlook.com>"
|
|
7
7
|
],
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"koishi": "^4.18.8"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
41
|
+
"segmentit": "^2.0.3"
|
|
42
42
|
}
|
|
43
43
|
}
|