koishi-plugin-chat-analyse 0.4.2 → 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.
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
@@ -546,11 +546,30 @@ var Stat = class {
546
546
  this.ctx = ctx;
547
547
  this.config = config;
548
548
  this.renderer = new Renderer(ctx);
549
+ this.setupCleanupTask();
549
550
  }
550
551
  static {
551
552
  __name(this, "Stat");
552
553
  }
553
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
+ }
554
573
  /**
555
574
  * @public
556
575
  * @method registerCommands
@@ -827,13 +846,13 @@ var WhoAt = class {
827
846
  * @private
828
847
  * @method setupCleanupTask
829
848
  * @description 设置一个定时清理任务。
830
- * 此任务会根据配置中的 `retentionDays` 定期删除过期的@记录,以防止数据库膨胀。
849
+ * 此任务会根据配置中的 `atRetentionDays` 定期删除过期的@记录,以防止数据库膨胀。
831
850
  */
832
851
  setupCleanupTask() {
833
- if (this.config.retentionDays > 0) {
852
+ if (this.config.atRetentionDays > 0) {
834
853
  this.ctx.cron("0 0 * * *", async () => {
835
854
  try {
836
- 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);
837
856
  await this.ctx.database.remove("analyse_at", { timestamp: { $lt: cutoffDate } });
838
857
  } catch (error) {
839
858
  this.ctx.logger.error("清理 @ 历史记录出错:", error);
@@ -896,12 +915,15 @@ var Config = import_koishi5.Schema.intersect([
896
915
  }).description("监听配置"),
897
916
  import_koishi5.Schema.object({
898
917
  enableCmdStat: import_koishi5.Schema.boolean().default(true).description("启用命令统计"),
899
- enableMsgStat: import_koishi5.Schema.boolean().default(true).description("启用消息统计"),
900
- enableRankStat: import_koishi5.Schema.boolean().default(true).description("启用发言排行")
901
- }).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("发言排行配置"),
902
924
  import_koishi5.Schema.object({
903
925
  enableWhoAt: import_koishi5.Schema.boolean().default(true).description("启用 @ 记录"),
904
- retentionDays: import_koishi5.Schema.number().min(0).default(7).description("保留天数")
926
+ atRetentionDays: import_koishi5.Schema.number().min(0).default(7).description("记录保留天数")
905
927
  }).description("@ 记录配置")
906
928
  ]);
907
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.2",
4
+ "version": "0.4.3",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],