koishi-plugin-chat-analyse 0.4.1 → 0.4.3

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.
@@ -34,6 +34,7 @@ declare module 'koishi' {
34
34
  timestamp: Date;
35
35
  };
36
36
  analyse_at: {
37
+ id: number;
37
38
  uid: number;
38
39
  target: string;
39
40
  content: string;
package/lib/Stat.d.ts CHANGED
@@ -15,6 +15,13 @@ export declare class Stat {
15
15
  * @param {Config} config - 插件的配置对象。
16
16
  */
17
17
  constructor(ctx: Context, config: Config);
18
+ /**
19
+ * @private
20
+ * @method setupCleanupTask
21
+ * @description 设置一个定时清理任务。
22
+ * 此任务会根据配置中的 `rankRetentionDays` 定期删除过期的发言排行数据,以防止数据库膨胀。
23
+ */
24
+ private setupCleanupTask;
18
25
  /**
19
26
  * @public
20
27
  * @method registerCommands
package/lib/WhoAt.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare class WhoAt {
21
21
  * @private
22
22
  * @method setupCleanupTask
23
23
  * @description 设置一个定时清理任务。
24
- * 此任务会根据配置中的 `retentionDays` 定期删除过期的@记录,以防止数据库膨胀。
24
+ * 此任务会根据配置中的 `atRetentionDays` 定期删除过期的@记录,以防止数据库膨胀。
25
25
  */
26
26
  private setupCleanupTask;
27
27
  /**
package/lib/index.d.ts CHANGED
@@ -17,7 +17,8 @@ export interface Config {
17
17
  enableRankStat: boolean;
18
18
  enableOriRecord: boolean;
19
19
  enableWhoAt: boolean;
20
- retentionDays: number;
20
+ atRetentionDays: number;
21
+ rankRetentionDays: number;
21
22
  }
22
23
  /**
23
24
  * @const {Schema<Config>} Config
package/lib/index.js CHANGED
@@ -55,7 +55,7 @@ var Collector = class _Collector {
55
55
  static FLUSH_INTERVAL = 60 * 1e3;
56
56
  /** @const {number} BUFFER_THRESHOLD - 内存缓存区触发自动刷新的消息数量阈值。 */
57
57
  static BUFFER_THRESHOLD = 100;
58
- // 分离的缓冲区
58
+ // 统一的缓冲区
59
59
  msgStatBuffer = /* @__PURE__ */ new Map();
60
60
  rankStatBuffer = /* @__PURE__ */ new Map();
61
61
  cmdStatBuffer = /* @__PURE__ */ new Map();
@@ -106,11 +106,12 @@ var Collector = class _Collector {
106
106
  }
107
107
  if (this.config.enableWhoAt) {
108
108
  this.ctx.model.extend("analyse_at", {
109
+ id: "unsigned",
109
110
  uid: "unsigned",
110
111
  target: "string",
111
112
  content: "text",
112
113
  timestamp: "timestamp"
113
- }, { indexes: ["target", "uid"] });
114
+ }, { primary: "id", autoInc: true, indexes: ["target", "uid"] });
114
115
  }
115
116
  }
116
117
  /**
@@ -545,11 +546,30 @@ var Stat = class {
545
546
  this.ctx = ctx;
546
547
  this.config = config;
547
548
  this.renderer = new Renderer(ctx);
549
+ this.setupCleanupTask();
548
550
  }
549
551
  static {
550
552
  __name(this, "Stat");
551
553
  }
552
554
  renderer;
555
+ /**
556
+ * @private
557
+ * @method setupCleanupTask
558
+ * @description 设置一个定时清理任务。
559
+ * 此任务会根据配置中的 `rankRetentionDays` 定期删除过期的发言排行数据,以防止数据库膨胀。
560
+ */
561
+ setupCleanupTask() {
562
+ if (this.config.rankRetentionDays > 0) {
563
+ this.ctx.cron("0 0 * * *", async () => {
564
+ try {
565
+ const cutoffDate = new Date(Date.now() - this.config.rankRetentionDays * import_koishi3.Time.day);
566
+ await this.ctx.database.remove("analyse_rank", { hour: { $lt: cutoffDate } });
567
+ } catch (error) {
568
+ this.ctx.logger.error("清理发言排行历史记录出错:", error);
569
+ }
570
+ });
571
+ }
572
+ }
553
573
  /**
554
574
  * @public
555
575
  * @method registerCommands
@@ -826,13 +846,13 @@ var WhoAt = class {
826
846
  * @private
827
847
  * @method setupCleanupTask
828
848
  * @description 设置一个定时清理任务。
829
- * 此任务会根据配置中的 `retentionDays` 定期删除过期的@记录,以防止数据库膨胀。
849
+ * 此任务会根据配置中的 `atRetentionDays` 定期删除过期的@记录,以防止数据库膨胀。
830
850
  */
831
851
  setupCleanupTask() {
832
- if (this.config.retentionDays > 0) {
852
+ if (this.config.atRetentionDays > 0) {
833
853
  this.ctx.cron("0 0 * * *", async () => {
834
854
  try {
835
- const cutoffDate = new Date(Date.now() - this.config.retentionDays * import_koishi4.Time.day);
855
+ const cutoffDate = new Date(Date.now() - this.config.atRetentionDays * import_koishi4.Time.day);
836
856
  await this.ctx.database.remove("analyse_at", { timestamp: { $lt: cutoffDate } });
837
857
  } catch (error) {
838
858
  this.ctx.logger.error("清理 @ 历史记录出错:", error);
@@ -895,12 +915,15 @@ var Config = import_koishi5.Schema.intersect([
895
915
  }).description("监听配置"),
896
916
  import_koishi5.Schema.object({
897
917
  enableCmdStat: import_koishi5.Schema.boolean().default(true).description("启用命令统计"),
898
- enableMsgStat: import_koishi5.Schema.boolean().default(true).description("启用消息统计"),
899
- enableRankStat: import_koishi5.Schema.boolean().default(true).description("启用发言排行")
900
- }).description("命令配置"),
918
+ enableMsgStat: import_koishi5.Schema.boolean().default(true).description("启用消息统计")
919
+ }).description("统计配置"),
920
+ import_koishi5.Schema.object({
921
+ enableRankStat: import_koishi5.Schema.boolean().default(true).description("启用发言排行"),
922
+ rankRetentionDays: import_koishi5.Schema.number().min(0).default(31).description("记录保留天数")
923
+ }).description("发言排行配置"),
901
924
  import_koishi5.Schema.object({
902
925
  enableWhoAt: import_koishi5.Schema.boolean().default(true).description("启用 @ 记录"),
903
- retentionDays: import_koishi5.Schema.number().min(0).default(7).description("保留天数")
926
+ atRetentionDays: import_koishi5.Schema.number().min(0).default(7).description("记录保留天数")
904
927
  }).description("@ 记录配置")
905
928
  ]);
906
929
  function apply(ctx, config) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-analyse",
3
3
  "description": "聊天记录分析",
4
- "version": "0.4.1",
4
+ "version": "0.4.3",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],