koishi-plugin-chat-analyse 0.5.4 → 0.5.5

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 +23 -4
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -504,11 +504,29 @@ var Stat = class {
504
504
  };
505
505
  }, "createHandler");
506
506
  if (this.config.enableCmdStat) {
507
- cmd.subcommand("cmdstat", "命令统计").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("all", "-a 全局").action(createHandler(async (scope) => {
507
+ cmd.subcommand("cmdstat", "命令统计").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("separate", "-h 分离展示").option("all", "-a 全局").action(createHandler(async (scope, options) => {
508
508
  const stats = await this.ctx.database.select("analyse_cmd").where({ uid: { $in: scope.uids } }).groupBy("command", { count: /* @__PURE__ */ __name((row) => import_koishi3.$.sum(row.count), "count"), lastUsed: /* @__PURE__ */ __name((row) => import_koishi3.$.max(row.timestamp), "lastUsed") }).orderBy("count", "desc").execute();
509
509
  if (stats.length === 0) return "暂无统计数据";
510
- const total = stats.reduce((sum, record) => sum + record.count, 0);
511
- const list = stats.map((item) => [item.command, item.count, item.lastUsed]);
510
+ let processedStats;
511
+ if (options.separate) {
512
+ processedStats = stats;
513
+ } else {
514
+ const mergedStatsMap = /* @__PURE__ */ new Map();
515
+ for (const stat of stats) {
516
+ const mainCommand = stat.command.split(".")[0];
517
+ const existing = mergedStatsMap.get(mainCommand) || { count: 0, lastUsed: /* @__PURE__ */ new Date(0) };
518
+ existing.count += stat.count;
519
+ if (stat.lastUsed > existing.lastUsed) existing.lastUsed = stat.lastUsed;
520
+ mergedStatsMap.set(mainCommand, existing);
521
+ }
522
+ processedStats = Array.from(mergedStatsMap.entries()).map(([command, data]) => ({
523
+ command,
524
+ count: data.count,
525
+ lastUsed: data.lastUsed
526
+ })).sort((a, b) => b.count - a.count);
527
+ }
528
+ const total = processedStats.reduce((sum, record) => sum + record.count, 0);
529
+ const list = processedStats.map((item) => [item.command, item.count, item.lastUsed]);
512
530
  const title = await this.generateTitle(scope.scopeDesc, { main: "命令" });
513
531
  return this.renderer.renderList({ title, time: /* @__PURE__ */ new Date(), total, list }, ["命令", "次数", "最后使用"]);
514
532
  }));
@@ -799,7 +817,8 @@ var Data = class {
799
817
  ]);
800
818
  const uniqueChannels = [...new Map(allChannelInfo.map((item) => [item.channelId, item])).values()];
801
819
  const channelOutput = uniqueChannels.length ? "频道列表:\n" + uniqueChannels.map((c) => `[${c.channelId}] ${c.channelName}`).join("\n") : "暂无频道记录";
802
- const commandOutput = commands.length ? "命令列表:\n" + commands.join(", ") : "暂无命令记录";
820
+ const commandNames = commands.map((c) => c.command);
821
+ const commandOutput = commandNames.length ? "命令列表:\n" + commandNames.join(", ") : "暂无命令记录";
803
822
  return `${channelOutput}
804
823
  ${commandOutput}`;
805
824
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "聊天记录分析",
4
- "version": "0.5.4",
4
+ "version": "0.5.5",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],