koishi-plugin-chat-analyse 1.7.5 → 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 CHANGED
@@ -13,7 +13,7 @@ export declare class Analyse {
13
13
  private ctx;
14
14
  private config;
15
15
  private renderer;
16
- private readonly jieba;
16
+ private readonly segmentit;
17
17
  constructor(ctx: Context, config: Config);
18
18
  /**
19
19
  * @public @method registerCommands
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 import_jieba = require("@node-rs/jieba");
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) this.jieba = import_jieba.Jieba.withDict(import_dict.dict);
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
- jieba = null;
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.jieba) return "Jieba 分词服务未就绪";
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.jieba.cut(allText).filter((w) => {
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;
@@ -2741,8 +2742,8 @@ var Config4 = import_koishi8.Schema.intersect([
2741
2742
  enableSimiActivity: import_koishi8.Schema.boolean().default(true).description("启用活跃比较"),
2742
2743
  enableRankStat: import_koishi8.Schema.boolean().default(true).description("启用发言排行"),
2743
2744
  enableWhoAt: import_koishi8.Schema.boolean().default(true).description("启用提及记录"),
2744
- rankRetentionDays: import_koishi8.Schema.number().min(0).default(365).description("排行保留天数"),
2745
- atRetentionDays: import_koishi8.Schema.number().min(0).default(3).description("提及保留天数")
2745
+ rankRetentionDays: import_koishi8.Schema.number().min(1).default(90).description("排行保留天数"),
2746
+ atRetentionDays: import_koishi8.Schema.number().min(1).default(7).description("提及保留天数")
2746
2747
  }).description("基础配置"),
2747
2748
  import_koishi8.Schema.object({
2748
2749
  enableOriRecord: import_koishi8.Schema.boolean().default(true).description("启用原始记录"),
@@ -2750,7 +2751,7 @@ var Config4 = import_koishi8.Schema.intersect([
2750
2751
  enableAiSummary: import_koishi8.Schema.boolean().default(false).description("启用模型分析"),
2751
2752
  tokenPerRequest: import_koishi8.Schema.number().default(32768).description("最大 Token 数"),
2752
2753
  enableAutoBackup: import_koishi8.Schema.boolean().default(true).description("启用自动归档"),
2753
- cacheRetentionDays: import_koishi8.Schema.number().min(0).default(7).description("记录保留天数"),
2754
+ cacheRetentionDays: import_koishi8.Schema.number().min(1).default(3).description("记录保留天数"),
2754
2755
  endpoints: import_koishi8.Schema.array(import_koishi8.Schema.object({
2755
2756
  url: import_koishi8.Schema.string().description("端点 (Endpoint)").role("link").required(),
2756
2757
  key: import_koishi8.Schema.string().description("密钥 (API Key)").role("secret"),
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.5",
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
- "@node-rs/jieba": "^2.0.1"
41
+ "segmentit": "^2.0.3"
42
42
  }
43
43
  }