koishi-plugin-chat-analyse 1.6.8 → 1.6.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.
- package/lib/index.d.ts +2 -1
- package/lib/index.js +10 -6
- package/package.json +1 -1
- package/readme.md +2 -1
package/lib/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface Config {
|
|
|
19
19
|
atRetentionDays: number;
|
|
20
20
|
rankRetentionDays: number;
|
|
21
21
|
enableWordCloud: boolean;
|
|
22
|
-
|
|
22
|
+
maxWords: number;
|
|
23
23
|
cacheRetentionDays: number;
|
|
24
24
|
enableSimilarActivity: boolean;
|
|
25
25
|
enableAutoBackup: boolean;
|
|
@@ -31,6 +31,7 @@ export interface Config {
|
|
|
31
31
|
rotationSteps: number;
|
|
32
32
|
fontFamily: string;
|
|
33
33
|
maskImage: string;
|
|
34
|
+
excludeWords: string;
|
|
34
35
|
}
|
|
35
36
|
/** @description 插件的配置项定义 */
|
|
36
37
|
export declare const Config: Schema<Config>;
|
package/lib/index.js
CHANGED
|
@@ -2132,7 +2132,7 @@ var Data = class {
|
|
|
2132
2132
|
this.ctx = ctx;
|
|
2133
2133
|
this.config = config;
|
|
2134
2134
|
this.dataDir = path.join(this.ctx.baseDir, "data", "chat-analyse");
|
|
2135
|
-
if (this.config.enableAutoBackup) this.ctx.cron("0
|
|
2135
|
+
if (this.config.enableAutoBackup) this.ctx.cron("0 0 * * *", () => {
|
|
2136
2136
|
this.backupCache();
|
|
2137
2137
|
});
|
|
2138
2138
|
}
|
|
@@ -2428,17 +2428,20 @@ var Analyse = class {
|
|
|
2428
2428
|
const since = new Date(Date.now() - options.hours * import_koishi6.Time.hour);
|
|
2429
2429
|
const records = await this.ctx.database.get("analyse_cache", { uid: { $in: scope.uids }, timestamp: { $gte: since } }, ["content"]);
|
|
2430
2430
|
if (!records.length) return "暂无统计数据";
|
|
2431
|
+
const excludeWords = new Set(this.config.excludeWords.split(",").map((w) => w.trim().toLowerCase()).filter(Boolean));
|
|
2431
2432
|
const exclusionRegex = /\[(face|file|forward|img|gif|audio|video|json|rps|markdown|dice|at:.*?)\]/g;
|
|
2432
2433
|
const allText = records.map((r) => r.content.replace(exclusionRegex, "")).join(" ");
|
|
2433
2434
|
const words = this.jieba.cut(allText).filter((w) => {
|
|
2434
|
-
|
|
2435
|
-
if (
|
|
2435
|
+
const trimmedWord = w.trim();
|
|
2436
|
+
if (trimmedWord.length <= 1) return false;
|
|
2437
|
+
if (/^\d+$/.test(trimmedWord)) return false;
|
|
2438
|
+
if (excludeWords.has(trimmedWord.toLowerCase())) return false;
|
|
2436
2439
|
return true;
|
|
2437
2440
|
});
|
|
2438
2441
|
if (!words.length) return "暂无有效词语";
|
|
2439
2442
|
const wordCounts = words.reduce((map, word) => map.set(word, (map.get(word) || 0) + 1), /* @__PURE__ */ new Map());
|
|
2440
2443
|
const wordList = Array.from(wordCounts.entries()).sort((a, b) => b[1] - a[1]);
|
|
2441
|
-
const limitedWordList = this.config.
|
|
2444
|
+
const limitedWordList = this.config.maxWords > 0 ? wordList.slice(0, this.config.maxWords) : wordList;
|
|
2442
2445
|
const topWordsPreview = limitedWordList.slice(0, 10).map((item) => item[0]).join(", ");
|
|
2443
2446
|
session.send(`正在基于 ${wordList.length} 个词生成词云:${topWordsPreview}...`);
|
|
2444
2447
|
const title = await generateTitle(this.ctx, scope.scopeDesc, { main: "词云", timeRange: options.hours });
|
|
@@ -2563,7 +2566,7 @@ var Config3 = import_koishi7.Schema.intersect([
|
|
|
2563
2566
|
enableSimilarActivity: import_koishi7.Schema.boolean().default(true).description("启用相似活跃分析")
|
|
2564
2567
|
}).description("高级分析配置"),
|
|
2565
2568
|
import_koishi7.Schema.object({
|
|
2566
|
-
|
|
2569
|
+
maxWords: import_koishi7.Schema.number().min(0).default(1024).description("最大词量"),
|
|
2567
2570
|
ellipticity: import_koishi7.Schema.number().min(0).max(1).default(1).description("长宽比"),
|
|
2568
2571
|
rotationSteps: import_koishi7.Schema.number().min(0).default(3).description("旋转步数"),
|
|
2569
2572
|
minRotation: import_koishi7.Schema.number().min(-Math.PI).max(Math.PI).default(-Math.PI / 2).description("最小旋转角"),
|
|
@@ -2571,7 +2574,8 @@ var Config3 = import_koishi7.Schema.intersect([
|
|
|
2571
2574
|
shape: import_koishi7.Schema.string().default("square").description("词云形状"),
|
|
2572
2575
|
color: import_koishi7.Schema.string().default("random-light").description("词云颜色"),
|
|
2573
2576
|
fontFamily: import_koishi7.Schema.string().default('"Noto Sans CJK SC", Arial, sans-serif').description("词云字体"),
|
|
2574
|
-
maskImage: import_koishi7.Schema.string().role("link").description("蒙版图片")
|
|
2577
|
+
maskImage: import_koishi7.Schema.string().role("link").description("蒙版图片"),
|
|
2578
|
+
excludeWords: import_koishi7.Schema.string().role("textarea").description("屏蔽词")
|
|
2575
2579
|
}).description("词云生成配置")
|
|
2576
2580
|
]);
|
|
2577
2581
|
async function parseQueryScope(ctx, session, options) {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -168,7 +168,8 @@
|
|
|
168
168
|
| `minRotation` | **最小旋转角**:单词随机旋转的最小角度(弧度)。 | `-1.570796` (-π/2) |
|
|
169
169
|
| `maxRotation` | **最大旋转角**:单词随机旋转的最大角度(弧度)。 | `1.570796` (π/2) |
|
|
170
170
|
| `rotationSteps`| **旋转步数**:旋转角度的选择方式。0表示随机,2表示只在最小/最大角度中二选一。 | `3` |
|
|
171
|
-
| `
|
|
171
|
+
| `maxWords`| **最大词量**:词云显示的最多词汇数量。 | `256` |
|
|
172
|
+
| `excludeWords`| **屏蔽词**:以下词汇不会显示在词云中。 | 例:`词汇1,词汇2` |
|
|
172
173
|
|
|
173
174
|
## 📌 注意事项
|
|
174
175
|
|