koishi-plugin-best-cave 2.0.7 → 2.0.8
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/DataManager.d.ts +1 -2
- package/lib/FileManager.d.ts +1 -2
- package/lib/ProfileManager.d.ts +1 -2
- package/lib/ReviewManager.d.ts +4 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +38 -47
- package/package.json +1 -1
package/lib/DataManager.d.ts
CHANGED
package/lib/FileManager.d.ts
CHANGED
package/lib/ProfileManager.d.ts
CHANGED
package/lib/ReviewManager.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { Context,
|
|
1
|
+
import { Context, Logger } from 'koishi';
|
|
2
2
|
import { CaveObject, Config } from './index';
|
|
3
3
|
import { FileManager } from './FileManager';
|
|
4
4
|
/**
|
|
5
5
|
* @class ReviewManager
|
|
6
|
-
* @description
|
|
7
|
-
* 负责处理回声洞的审核流程。当 `enableReview` 配置开启时,
|
|
8
|
-
* 此管理器将被激活,处理新洞的提交、审核通知和审核操作。
|
|
6
|
+
* @description 负责处理回声洞的审核流程,处理新洞的提交、审核通知和审核操作。
|
|
9
7
|
*/
|
|
10
8
|
export declare class ReviewManager {
|
|
11
9
|
private ctx;
|
|
@@ -26,7 +24,7 @@ export declare class ReviewManager {
|
|
|
26
24
|
*/
|
|
27
25
|
registerCommands(cave: any): void;
|
|
28
26
|
/**
|
|
29
|
-
* @description
|
|
27
|
+
* @description 将新回声洞提交到管理群组以供审核。
|
|
30
28
|
* @param cave 新创建的、状态为 'pending' 的回声洞对象。
|
|
31
29
|
*/
|
|
32
30
|
sendForReview(cave: CaveObject): Promise<void>;
|
|
@@ -34,8 +32,7 @@ export declare class ReviewManager {
|
|
|
34
32
|
* @description 处理管理员的审核决定(通过或拒绝)。
|
|
35
33
|
* @param action 'approve' (通过) 或 'reject' (拒绝)。
|
|
36
34
|
* @param caveId 被审核的回声洞 ID。
|
|
37
|
-
* @param adminUserName 操作管理员的昵称。
|
|
38
35
|
* @returns 返回给操作者的确认消息。
|
|
39
36
|
*/
|
|
40
|
-
processReview(action: 'approve' | 'reject', caveId: number
|
|
37
|
+
processReview(action: 'approve' | 'reject', caveId: number): Promise<string>;
|
|
41
38
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -37,7 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
usage: () => usage
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(index_exports);
|
|
40
|
-
var
|
|
40
|
+
var import_koishi3 = require("koishi");
|
|
41
41
|
var path3 = __toESM(require("path"));
|
|
42
42
|
|
|
43
43
|
// src/FileManager.ts
|
|
@@ -296,7 +296,7 @@ async function getNextCaveId(ctx, query = {}) {
|
|
|
296
296
|
}
|
|
297
297
|
__name(getNextCaveId, "getNextCaveId");
|
|
298
298
|
function checkCooldown(session, config, lastUsed) {
|
|
299
|
-
if (config.coolDown <= 0 || !session.channelId
|
|
299
|
+
if (config.coolDown <= 0 || !session.channelId) return null;
|
|
300
300
|
const now = Date.now();
|
|
301
301
|
const lastTime = lastUsed.get(session.channelId) || 0;
|
|
302
302
|
if (now - lastTime < config.coolDown * 1e3) {
|
|
@@ -337,7 +337,7 @@ var DataManager = class {
|
|
|
337
337
|
*/
|
|
338
338
|
registerCommands(cave) {
|
|
339
339
|
cave.subcommand(".export", "导出回声洞数据").usage("将所有回声洞数据导出到 cave_export.json。").action(async ({ session }) => {
|
|
340
|
-
if (
|
|
340
|
+
if (session.channelId !== this.config.adminChannel) return "此指令仅限在管理群组中使用";
|
|
341
341
|
try {
|
|
342
342
|
await session.send("正在导出数据,请稍候...");
|
|
343
343
|
return await this.exportData();
|
|
@@ -347,7 +347,7 @@ var DataManager = class {
|
|
|
347
347
|
}
|
|
348
348
|
});
|
|
349
349
|
cave.subcommand(".import", "导入回声洞数据").usage("从 cave_import.json 中导入回声洞数据。").action(async ({ session }) => {
|
|
350
|
-
if (
|
|
350
|
+
if (session.channelId !== this.config.adminChannel) return "此指令仅限在管理群组中使用";
|
|
351
351
|
try {
|
|
352
352
|
await session.send("正在导入数据,请稍候...");
|
|
353
353
|
return await this.importData();
|
|
@@ -393,7 +393,6 @@ var DataManager = class {
|
|
|
393
393
|
channelId: cave.channelId || null,
|
|
394
394
|
// 保证 channelId 存在
|
|
395
395
|
status: "active"
|
|
396
|
-
// 导入的数据直接设为活跃状态
|
|
397
396
|
};
|
|
398
397
|
await this.ctx.database.create("cave", newCave);
|
|
399
398
|
successCount++;
|
|
@@ -403,6 +402,7 @@ var DataManager = class {
|
|
|
403
402
|
};
|
|
404
403
|
|
|
405
404
|
// src/ReviewManager.ts
|
|
405
|
+
var import_koishi2 = require("koishi");
|
|
406
406
|
var ReviewManager = class {
|
|
407
407
|
/**
|
|
408
408
|
* @constructor
|
|
@@ -426,7 +426,7 @@ var ReviewManager = class {
|
|
|
426
426
|
*/
|
|
427
427
|
registerCommands(cave) {
|
|
428
428
|
cave.subcommand(".review [id:posint] [action:string]", "审核回声洞").usage("查看或审核回声洞,使用 <Y/N> 进行审核。").action(async ({ session }, id, action) => {
|
|
429
|
-
if (
|
|
429
|
+
if (session.channelId !== this.config.adminChannel) return "此指令仅限在管理群组中使用";
|
|
430
430
|
if (!id) {
|
|
431
431
|
const pendingCaves = await this.ctx.database.get("cave", { status: "pending" });
|
|
432
432
|
if (pendingCaves.length === 0) return "当前没有需要审核的回声洞";
|
|
@@ -445,53 +445,44 @@ ${pendingCaves.map((c) => c.id).join(", ")}`;
|
|
|
445
445
|
else if (["n", "no", "deny", "reject"].includes(normalizedAction)) reviewAction = "reject";
|
|
446
446
|
else return `无效操作: "${action}"
|
|
447
447
|
请使用 "Y" (通过) 或 "N" (拒绝)`;
|
|
448
|
-
return this.processReview(reviewAction, id
|
|
448
|
+
return this.processReview(reviewAction, id);
|
|
449
449
|
});
|
|
450
450
|
}
|
|
451
451
|
/**
|
|
452
|
-
* @description
|
|
452
|
+
* @description 将新回声洞提交到管理群组以供审核。
|
|
453
453
|
* @param cave 新创建的、状态为 'pending' 的回声洞对象。
|
|
454
454
|
*/
|
|
455
455
|
async sendForReview(cave) {
|
|
456
|
-
if (!this.config.
|
|
457
|
-
this.logger.warn(
|
|
456
|
+
if (!this.config.adminChannel) {
|
|
457
|
+
this.logger.warn(`未配置管理群组,已自动通过回声洞(${cave.id})`);
|
|
458
458
|
await this.ctx.database.upsert("cave", [{ id: cave.id, status: "active" }]);
|
|
459
459
|
return;
|
|
460
460
|
}
|
|
461
461
|
const reviewMessage = [`待审核:`, ...await buildCaveMessage(cave, this.config, this.fileManager, this.logger)];
|
|
462
462
|
try {
|
|
463
|
-
await this.ctx.broadcast(this.config.
|
|
463
|
+
await this.ctx.broadcast([this.config.adminChannel], import_koishi2.h.normalize(reviewMessage));
|
|
464
464
|
} catch (error) {
|
|
465
|
-
this.logger.error(
|
|
465
|
+
this.logger.error(`发送回声洞(${cave.id})审核消息失败:`, error);
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
/**
|
|
469
469
|
* @description 处理管理员的审核决定(通过或拒绝)。
|
|
470
470
|
* @param action 'approve' (通过) 或 'reject' (拒绝)。
|
|
471
471
|
* @param caveId 被审核的回声洞 ID。
|
|
472
|
-
* @param adminUserName 操作管理员的昵称。
|
|
473
472
|
* @returns 返回给操作者的确认消息。
|
|
474
473
|
*/
|
|
475
|
-
async processReview(action, caveId
|
|
474
|
+
async processReview(action, caveId) {
|
|
476
475
|
const [cave] = await this.ctx.database.get("cave", { id: caveId, status: "pending" });
|
|
477
|
-
if (!cave) return `回声洞(${caveId}
|
|
476
|
+
if (!cave) return `回声洞(${caveId})无需审核`;
|
|
478
477
|
let resultMessage;
|
|
479
|
-
let broadcastMessage;
|
|
480
478
|
if (action === "approve") {
|
|
481
479
|
await this.ctx.database.upsert("cave", [{ id: caveId, status: "active" }]);
|
|
482
480
|
resultMessage = `回声洞(${caveId})已通过`;
|
|
483
|
-
broadcastMessage = `回声洞(${caveId})已由管理员 "${adminUserName}" 通过`;
|
|
484
481
|
} else {
|
|
485
482
|
await this.ctx.database.upsert("cave", [{ id: caveId, status: "delete" }]);
|
|
486
483
|
resultMessage = `回声洞(${caveId})已拒绝`;
|
|
487
|
-
broadcastMessage = `回声洞(${caveId})已由管理员 "${adminUserName}" 拒绝`;
|
|
488
484
|
cleanupPendingDeletions(this.ctx, this.fileManager, this.logger);
|
|
489
485
|
}
|
|
490
|
-
if (this.config.adminUsers?.length) {
|
|
491
|
-
this.ctx.broadcast(this.config.adminUsers, broadcastMessage).catch((err) => {
|
|
492
|
-
this.logger.error(`广播回声洞(${cave.id})审核结果失败:`, err);
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
486
|
return resultMessage;
|
|
496
487
|
}
|
|
497
488
|
};
|
|
@@ -511,28 +502,28 @@ var usage = `
|
|
|
511
502
|
<p>🐛 遇到问题?请通过 <strong>Issues</strong> 提交反馈,或加入 QQ 群 <a href="https://qm.qq.com/q/PdLMx9Jowq" style="color:#e0574a;text-decoration:none;"><strong>855571375</strong></a> 进行交流</p>
|
|
512
503
|
</div>
|
|
513
504
|
`;
|
|
514
|
-
var logger = new
|
|
515
|
-
var Config =
|
|
516
|
-
|
|
517
|
-
coolDown:
|
|
518
|
-
perChannel:
|
|
519
|
-
enableProfile:
|
|
520
|
-
enableIO:
|
|
521
|
-
|
|
522
|
-
|
|
505
|
+
var logger = new import_koishi3.Logger("best-cave");
|
|
506
|
+
var Config = import_koishi3.Schema.intersect([
|
|
507
|
+
import_koishi3.Schema.object({
|
|
508
|
+
coolDown: import_koishi3.Schema.number().default(10).description("冷却时间(秒)"),
|
|
509
|
+
perChannel: import_koishi3.Schema.boolean().default(false).description("启用分群模式"),
|
|
510
|
+
enableProfile: import_koishi3.Schema.boolean().default(false).description("启用自定义昵称"),
|
|
511
|
+
enableIO: import_koishi3.Schema.boolean().default(false).description("启用导入导出"),
|
|
512
|
+
adminChannel: import_koishi3.Schema.string().description("管理群组 ID"),
|
|
513
|
+
caveFormat: import_koishi3.Schema.string().default("回声洞 ——({id})|—— {name}").description("自定义文本")
|
|
523
514
|
}).description("基础配置"),
|
|
524
|
-
|
|
525
|
-
enableReview:
|
|
515
|
+
import_koishi3.Schema.object({
|
|
516
|
+
enableReview: import_koishi3.Schema.boolean().default(false).description("启用审核")
|
|
526
517
|
}).description("审核配置"),
|
|
527
|
-
|
|
528
|
-
localPath:
|
|
529
|
-
enableS3:
|
|
530
|
-
publicUrl:
|
|
531
|
-
endpoint:
|
|
532
|
-
bucket:
|
|
533
|
-
region:
|
|
534
|
-
accessKeyId:
|
|
535
|
-
secretAccessKey:
|
|
518
|
+
import_koishi3.Schema.object({
|
|
519
|
+
localPath: import_koishi3.Schema.string().description("文件映射路径"),
|
|
520
|
+
enableS3: import_koishi3.Schema.boolean().default(false).description("启用 S3 存储"),
|
|
521
|
+
publicUrl: import_koishi3.Schema.string().description("公共访问 URL").role("link"),
|
|
522
|
+
endpoint: import_koishi3.Schema.string().description("端点 (Endpoint)").role("link"),
|
|
523
|
+
bucket: import_koishi3.Schema.string().description("存储桶 (Bucket)"),
|
|
524
|
+
region: import_koishi3.Schema.string().default("auto").description("区域 (Region)"),
|
|
525
|
+
accessKeyId: import_koishi3.Schema.string().description("Access Key ID").role("secret"),
|
|
526
|
+
secretAccessKey: import_koishi3.Schema.string().description("Secret Access Key").role("secret")
|
|
536
527
|
}).description("存储配置")
|
|
537
528
|
]);
|
|
538
529
|
function apply(ctx, config) {
|
|
@@ -578,12 +569,12 @@ function apply(ctx, config) {
|
|
|
578
569
|
if (session.quote?.elements) {
|
|
579
570
|
sourceElements = session.quote.elements;
|
|
580
571
|
} else if (content?.trim()) {
|
|
581
|
-
sourceElements =
|
|
572
|
+
sourceElements = import_koishi3.h.parse(content);
|
|
582
573
|
} else {
|
|
583
574
|
await session.send("请在一分钟内发送你要添加的内容");
|
|
584
575
|
const reply = await session.prompt(6e4);
|
|
585
576
|
if (!reply) return "操作超时,已取消添加";
|
|
586
|
-
sourceElements =
|
|
577
|
+
sourceElements = import_koishi3.h.parse(reply);
|
|
587
578
|
}
|
|
588
579
|
const idScopeQuery = {};
|
|
589
580
|
if (config.perChannel && session.channelId) {
|
|
@@ -682,8 +673,8 @@ function apply(ctx, config) {
|
|
|
682
673
|
try {
|
|
683
674
|
const [targetCave] = await ctx.database.get("cave", { id, status: "active" });
|
|
684
675
|
if (!targetCave) return `回声洞(${id})不存在`;
|
|
685
|
-
if (targetCave.userId !== session.userId &&
|
|
686
|
-
return "
|
|
676
|
+
if (targetCave.userId !== session.userId && session.channelId !== config.adminChannel) {
|
|
677
|
+
return "你没有权限删除这条回声洞";
|
|
687
678
|
}
|
|
688
679
|
await ctx.database.upsert("cave", [{ id, status: "delete" }]);
|
|
689
680
|
const caveMessage = await buildCaveMessage(targetCave, config, fileManager, logger);
|