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 +7 -0
- package/lib/WhoAt.d.ts +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +29 -7
- package/package.json +1 -1
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
package/lib/index.d.ts
CHANGED
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
|
-
* 此任务会根据配置中的 `
|
|
849
|
+
* 此任务会根据配置中的 `atRetentionDays` 定期删除过期的@记录,以防止数据库膨胀。
|
|
831
850
|
*/
|
|
832
851
|
setupCleanupTask() {
|
|
833
|
-
if (this.config.
|
|
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.
|
|
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
|
-
|
|
901
|
-
|
|
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
|
-
|
|
926
|
+
atRetentionDays: import_koishi5.Schema.number().min(0).default(7).description("记录保留天数")
|
|
905
927
|
}).description("@ 记录配置")
|
|
906
928
|
]);
|
|
907
929
|
function apply(ctx, config) {
|