koishi-plugin-chat-analyse 1.4.1 → 1.4.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 -7
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2281,10 +2281,9 @@ var Data = class {
2281
2281
  }
2282
2282
  });
2283
2283
  if (this.config.enableOriRecord) {
2284
- cmd.subcommand(".view <time:string>", "查询消息记录", { authority: 4 }).usage("查询指定时间点后的消息记录,默认查询当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").action(async ({ session, options }, time) => {
2285
- if (!time) return '请以"YYYY-MM-DD HH:MM:SS"格式输入起始时间';
2286
- const since = new Date(time);
2287
- if (isNaN(since.getTime())) return "时间格式无效";
2284
+ cmd.subcommand(".view [time:string]", "查询消息记录", { authority: 4 }).usage("查询指定时间点之前的消息记录,默认查询当前群组。").option("user", "-u <user:string> 指定用户").option("guild", "-g <guildId:string> 指定群组").option("count", "-n <count:number> 指定数量", { fallback: 100 }).action(async ({ session, options }, time) => {
2285
+ const until = time ? new Date(time) : /* @__PURE__ */ new Date();
2286
+ if (time && isNaN(until.getTime())) return "时间格式无效";
2288
2287
  try {
2289
2288
  const userQuery = {};
2290
2289
  if (!options.guild && !options.user) {
@@ -2299,12 +2298,13 @@ var Data = class {
2299
2298
  const uids = usersInScope.map((u) => u.uid);
2300
2299
  const records = await this.ctx.database.get("analyse_cache", {
2301
2300
  uid: { $in: uids },
2302
- timestamp: { $gte: since }
2301
+ timestamp: { $lte: until }
2303
2302
  }, {
2304
- sort: { timestamp: "asc" },
2305
- limit: 100
2303
+ sort: { timestamp: "desc" },
2304
+ limit: options.count
2306
2305
  });
2307
2306
  if (records.length === 0) return "暂无统计数据";
2307
+ records.reverse();
2308
2308
  const recordUids = [...new Set(records.map((r) => r.uid))];
2309
2309
  const users = await this.ctx.database.get("analyse_user", { uid: { $in: recordUids } }, ["uid", "userName", "userId"]);
2310
2310
  const userInfoMap = new Map(users.map((u) => [u.uid, { name: u.userName, id: u.userId }]));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "强大而全面的聊天数据分析插件。支持多维度统计(命令、发言、消息类型、活跃度),可生成发言排行、词云图,并提供完善的数据管理。",
4
- "version": "1.4.1",
4
+ "version": "1.4.2",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],