koishi-plugin-chat-analyse 0.6.0 → 0.6.2

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.
Files changed (2) hide show
  1. package/lib/index.js +7 -4
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -839,6 +839,7 @@ var Analyse = class {
839
839
  this.config = config;
840
840
  this.renderer = new Renderer(ctx);
841
841
  this.nlp = new import_basic.Nlp({ languages: ["zh"], nlu: { log: false } });
842
+ this.nlp.settings.autoSave = false;
842
843
  this.nlp.container.register("extract-lang-zh", new import_lang_zh.LangZh());
843
844
  this.initializeNlp().catch((err) => {
844
845
  this.ctx.logger.error("NLP 语言模型加载失败:", err);
@@ -861,11 +862,12 @@ var Analyse = class {
861
862
  }
862
863
  registerCommands(cmd) {
863
864
  if (this.config.enableWordCloud) {
864
- cmd.subcommand(".wordcloud", "生成词云", { checkArgCount: false }).usage("基于指定范围内的聊天记录生成词云图。").option("guild", "-g <guildId:string> 指定群组").option("user", "-u <user:string> 指定用户").option("all", "-a 全局").action(async ({ session, options }) => {
865
+ cmd.subcommand(".wordcloud", "生成词云").usage("基于指定范围内的聊天记录生成词云图。").option("guild", "-g <guildId:string> 指定群组").option("user", "-u <user:string> 指定用户").option("all", "-a 全局").option("hours", "-h <hours:number> 指定时长", { fallback: 24 }).action(async ({ session, options }) => {
865
866
  if (!this.isNlpReady) return "文本分析尚未就绪,请稍后再试";
866
867
  const scope = await parseQueryScope(this.ctx, session, options);
867
868
  if (scope.error) return scope.error;
868
- const records = await this.ctx.database.select("analyse_cache").where({ uid: { $in: scope.uids } }).project(["content"]).execute();
869
+ const since = new Date(Date.now() - options.hours * import_koishi6.Time.hour);
870
+ const records = await this.ctx.database.select("analyse_cache").where({ uid: { $in: scope.uids }, timestamp: { $gte: since } }).project(["content"]).execute();
869
871
  if (records.length === 0) return "暂无统计数据";
870
872
  const allText = records.map((r) => r.content).join(" ");
871
873
  const result = await this.nlp.process("zh", allText);
@@ -885,13 +887,14 @@ var Analyse = class {
885
887
  });
886
888
  }
887
889
  if (this.config.enableVocabulary) {
888
- cmd.subcommand(".vocabulary", "词汇排行", { checkArgCount: false }).usage("根据不重复词汇量占总词汇量的比例进行排行。").option("guild", "-g <guildId:string> 指定群组").option("all", "-a 全局").action(async ({ session, options }) => {
890
+ cmd.subcommand(".vocabulary", "词汇排行").usage("根据不重复词汇量占总词汇量的比例进行排行。").option("guild", "-g <guildId:string> 指定群组").option("all", "-a 全局").option("hours", "-h <hours:number> 指定时长", { fallback: 24 }).action(async ({ session, options }) => {
889
891
  if (!this.isNlpReady) return "文本分析尚未就绪,请稍后再试";
890
892
  const scope = await parseQueryScope(this.ctx, session, options);
891
893
  if (scope.error) return scope.error;
892
894
  const users = await this.ctx.database.get("analyse_user", { uid: { $in: scope.uids } }, ["uid", "userName"]);
893
895
  const userNameMap = new Map(users.map((u) => [u.uid, u.userName]));
894
- const allRecords = await this.ctx.database.get("analyse_cache", { uid: { $in: scope.uids } }, ["uid", "content"]);
896
+ const since = new Date(Date.now() - options.hours * import_koishi6.Time.hour);
897
+ const allRecords = await this.ctx.database.get("analyse_cache", { uid: { $in: scope.uids }, timestamp: { $gte: since } }, ["uid", "content"]);
895
898
  if (allRecords.length === 0) return "暂无统计数据";
896
899
  const messagesByUid = /* @__PURE__ */ new Map();
897
900
  for (const record of allRecords) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "聊天记录分析",
4
- "version": "0.6.0",
4
+ "version": "0.6.2",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],
@@ -39,7 +39,7 @@
39
39
  "koishi": "4.18.8"
40
40
  },
41
41
  "dependencies": {
42
- "@nlpjs/basic": "^5.0.0-alpha.5",
43
- "@nlpjs/lang-zh": "^5.0.0-alpha.5"
42
+ "@nlpjs/basic": "^4.26.1",
43
+ "@nlpjs/lang-zh": "^4.26.1"
44
44
  }
45
45
  }