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.
@@ -3,8 +3,7 @@ import { FileManager } from './FileManager';
3
3
  import { Config } from './index';
4
4
  /**
5
5
  * @class DataManager
6
- * @description
7
- * 负责处理回声洞数据的导入和导出功能。
6
+ * @description 负责处理回声洞数据的导入和导出功能。
8
7
  */
9
8
  export declare class DataManager {
10
9
  private ctx;
@@ -2,8 +2,7 @@ import { Logger } from 'koishi';
2
2
  import { Config } from './index';
3
3
  /**
4
4
  * @class FileManager
5
- * @description
6
- * 封装了对文件的存储、读取和删除操作。
5
+ * @description 封装了对文件的存储、读取和删除操作。
7
6
  * 能根据配置自动选择使用本地文件系统或 AWS S3 作为存储后端。
8
7
  * 内置 Promise 文件锁,防止本地文件的并发写入冲突。
9
8
  */
@@ -15,8 +15,7 @@ declare module 'koishi' {
15
15
  }
16
16
  /**
17
17
  * @class ProfileManager
18
- * @description
19
- * 负责管理用户在回声洞中的自定义昵称。
18
+ * @description 负责管理用户在回声洞中的自定义昵称。
20
19
  * 当插件配置 `enableProfile` 为 true 时实例化。
21
20
  */
22
21
  export declare class ProfileManager {
@@ -1,11 +1,9 @@
1
- import { Context, h, Logger } from 'koishi';
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, adminUserName: string): Promise<string | (string | h)[]>;
37
+ processReview(action: 'approve' | 'reject', caveId: number): Promise<string>;
41
38
  }
package/lib/index.d.ts CHANGED
@@ -30,7 +30,7 @@ declare module 'koishi' {
30
30
  export interface Config {
31
31
  coolDown: number;
32
32
  perChannel: boolean;
33
- adminUsers: string[];
33
+ adminChannel: string;
34
34
  enableProfile: boolean;
35
35
  enableIO: boolean;
36
36
  enableReview: boolean;
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 import_koishi2 = require("koishi");
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 || config.adminUsers.includes(session.userId)) return null;
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 (!this.config.adminUsers.includes(session.userId)) return "抱歉,你没有权限导出数据";
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 (!this.config.adminUsers.includes(session.userId)) return "抱歉,你没有权限导入数据";
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 (!this.config.adminUsers.includes(session.userId)) return "抱歉,你没有权限执行审核";
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, session.username);
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.adminUsers?.length) {
457
- this.logger.warn(`未配置管理员,回声洞(${cave.id})已自动通过审核`);
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.adminUsers, reviewMessage);
463
+ await this.ctx.broadcast([this.config.adminChannel], import_koishi2.h.normalize(reviewMessage));
464
464
  } catch (error) {
465
- this.logger.error(`广播回声洞(${cave.id})审核请求失败:`, 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, adminUserName) {
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 import_koishi2.Logger("best-cave");
515
- var Config = import_koishi2.Schema.intersect([
516
- import_koishi2.Schema.object({
517
- coolDown: import_koishi2.Schema.number().default(10).description("冷却时间(秒)"),
518
- perChannel: import_koishi2.Schema.boolean().default(false).description("启用分群模式"),
519
- enableProfile: import_koishi2.Schema.boolean().default(false).description("启用自定义昵称"),
520
- enableIO: import_koishi2.Schema.boolean().default(false).description("启用导入导出"),
521
- caveFormat: import_koishi2.Schema.string().default("回声洞 ——({id})|—— {name}").description("自定义文本"),
522
- adminUsers: import_koishi2.Schema.array(import_koishi2.Schema.string()).default([]).description("管理员 ID 列表")
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
- import_koishi2.Schema.object({
525
- enableReview: import_koishi2.Schema.boolean().default(false).description("启用审核")
515
+ import_koishi3.Schema.object({
516
+ enableReview: import_koishi3.Schema.boolean().default(false).description("启用审核")
526
517
  }).description("审核配置"),
527
- import_koishi2.Schema.object({
528
- localPath: import_koishi2.Schema.string().description("文件映射路径"),
529
- enableS3: import_koishi2.Schema.boolean().default(false).description("启用 S3 存储"),
530
- publicUrl: import_koishi2.Schema.string().description("公共访问 URL").role("link"),
531
- endpoint: import_koishi2.Schema.string().description("端点 (Endpoint)").role("link"),
532
- bucket: import_koishi2.Schema.string().description("存储桶 (Bucket)"),
533
- region: import_koishi2.Schema.string().default("auto").description("区域 (Region)"),
534
- accessKeyId: import_koishi2.Schema.string().description("Access Key ID").role("secret"),
535
- secretAccessKey: import_koishi2.Schema.string().description("Secret Access Key").role("secret")
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 = import_koishi2.h.parse(content);
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 = import_koishi2.h.parse(reply);
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 && !config.adminUsers.includes(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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "最强大的回声洞现已重构完成啦!注意数据格式需要使用脚本转换哦~",
4
- "version": "2.0.7",
4
+ "version": "2.0.8",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],