koishi-plugin-best-cave 2.4.3 → 2.4.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.
- package/lib/index.js +22 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -558,15 +558,20 @@ ${pendingCaves.map((c) => c.id).join("|")}`;
|
|
|
558
558
|
const createPendAction = /* @__PURE__ */ __name((actionType) => async ({ session }, ...ids) => {
|
|
559
559
|
const adminError = requireAdmin(session);
|
|
560
560
|
if (adminError) return adminError;
|
|
561
|
-
|
|
561
|
+
let idsToProcess = ids;
|
|
562
|
+
if (idsToProcess.length === 0) {
|
|
563
|
+
const pendingCaves = await this.ctx.database.get("cave", { status: "pending" }, { fields: ["id"] });
|
|
564
|
+
if (!pendingCaves.length) return "当前没有需要审核的回声洞";
|
|
565
|
+
idsToProcess = pendingCaves.map((c) => c.id);
|
|
566
|
+
}
|
|
562
567
|
try {
|
|
563
568
|
const targetStatus = actionType === "approve" ? "active" : "delete";
|
|
564
569
|
const actionText = actionType === "approve" ? "通过" : "拒绝";
|
|
565
570
|
const cavesToProcess = await this.ctx.database.get("cave", {
|
|
566
|
-
id: { $in:
|
|
571
|
+
id: { $in: idsToProcess },
|
|
567
572
|
status: "pending"
|
|
568
573
|
});
|
|
569
|
-
if (cavesToProcess.length === 0) return `回声洞(${
|
|
574
|
+
if (cavesToProcess.length === 0) return `回声洞(${idsToProcess.join("|")})无需审核或不存在`;
|
|
570
575
|
const processedIds = cavesToProcess.map((cave2) => cave2.id);
|
|
571
576
|
await this.ctx.database.upsert("cave", processedIds.map((id) => ({ id, status: targetStatus })));
|
|
572
577
|
if (targetStatus === "delete") cleanupPendingDeletions(this.ctx, this.fileManager, this.logger, this.reusableIds);
|
|
@@ -576,8 +581,8 @@ ${pendingCaves.map((c) => c.id).join("|")}`;
|
|
|
576
581
|
return `操作失败: ${error.message}`;
|
|
577
582
|
}
|
|
578
583
|
}, "createPendAction");
|
|
579
|
-
pend.subcommand(".Y [...ids:posint]", "通过审核").usage("通过一个或多个指定 ID
|
|
580
|
-
pend.subcommand(".N [...ids:posint]", "拒绝审核").usage("拒绝一个或多个指定 ID
|
|
584
|
+
pend.subcommand(".Y [...ids:posint]", "通过审核").usage("通过一个或多个指定 ID 的回声洞审核。若不指定 ID,则通过所有待审核的回声洞。").action(createPendAction("approve"));
|
|
585
|
+
pend.subcommand(".N [...ids:posint]", "拒绝审核").usage("拒绝一个或多个指定 ID 的回声洞审核。若不指定 ID,则拒绝所有待审核的回声洞。").action(createPendAction("reject"));
|
|
581
586
|
}
|
|
582
587
|
/**
|
|
583
588
|
* @description 将新回声洞提交到管理群组以供审核。
|
|
@@ -1003,6 +1008,18 @@ function apply(ctx, config) {
|
|
|
1003
1008
|
const reviewManager = config.enablePend ? new PendManager(ctx, config, fileManager, logger, reusableIds) : null;
|
|
1004
1009
|
const hashManager = config.enableSimilarity ? new HashManager(ctx, config, logger, fileManager) : null;
|
|
1005
1010
|
const dataManager = config.enableIO ? new DataManager(ctx, config, fileManager, logger) : null;
|
|
1011
|
+
ctx.on("ready", async () => {
|
|
1012
|
+
try {
|
|
1013
|
+
const staleCaves = await ctx.database.get("cave", { status: "preload" });
|
|
1014
|
+
if (staleCaves.length > 0) {
|
|
1015
|
+
const idsToMark = staleCaves.map((c) => ({ id: c.id, status: "delete" }));
|
|
1016
|
+
await ctx.database.upsert("cave", idsToMark);
|
|
1017
|
+
await cleanupPendingDeletions(ctx, fileManager, logger, reusableIds);
|
|
1018
|
+
}
|
|
1019
|
+
} catch (error) {
|
|
1020
|
+
logger.error("清理残留回声洞时发生错误:", error);
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1006
1023
|
const cave = ctx.command("cave", "回声洞").option("add", "-a <content:text> 添加回声洞").option("view", "-g <id:posint> 查看指定回声洞").option("delete", "-r <id:posint> 删除指定回声洞").option("list", "-l 查询投稿统计").usage("随机抽取一条已添加的回声洞。").action(async ({ session, options }) => {
|
|
1007
1024
|
if (options.add) return session.execute(`cave.add ${options.add}`);
|
|
1008
1025
|
if (options.view) return session.execute(`cave.view ${options.view}`);
|