koishi-plugin-echo-cave 1.16.2 → 1.16.4

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.cjs CHANGED
@@ -372,36 +372,12 @@ async function getUserName(ctx, session, userId) {
372
372
  return userId;
373
373
  }
374
374
  }
375
- async function checkUsersInGroupDebug(ctx, session, userIds) {
375
+ async function checkUsersInGroup(ctx, session, userIds) {
376
376
  try {
377
- const channelId = session.channelId;
378
- console.log(`
379
- === \u8C03\u8BD5\u4FE1\u606F\uFF1AcheckUsersInGroupDebug ===`);
380
- console.log(`channelId: ${channelId}`);
381
- const groupMembers = await session.onebot.getGroupMemberList(channelId);
382
- console.log(`\u7FA4\u6210\u5458\u6570\u91CF\uFF1A${groupMembers.length}`);
383
- console.log(`\u7FA4\u6210\u5458ID\u5217\u8868\uFF1A${groupMembers.map((member) => member.user_id).join(", ")}`);
377
+ const groupMembers = await session.onebot.getGroupMemberList(session.channelId);
384
378
  const memberIds = groupMembers.map((member) => member.user_id.toString());
385
- const userIdsSet = new Set(userIds);
386
- console.log(`\u68C0\u67E5\u7684\u7528\u6237ID\uFF1A${userIds.join(", ")}`);
387
- const usersNotHere = userIds.filter((userId) => !memberIds.includes(userId));
388
- if (usersNotHere.length > 0) {
389
- console.log(`\u274C \u4E0D\u5728\u7FA4\u7EC4\u7684\u7528\u6237ID\uFF1A${usersNotHere.join(", ")}`);
390
- console.log(`=== \u8C03\u8BD5\u7ED3\u675F ===
391
- `);
392
- return false;
393
- } else {
394
- console.log(`\u2705 \u6240\u6709\u7528\u6237\u90FD\u5728\u7FA4\u7EC4\u4E2D`);
395
- console.log(`=== \u8C03\u8BD5\u7ED3\u675F ===
396
- `);
397
- return true;
398
- }
379
+ return userIds.every((userId) => memberIds.includes(userId));
399
380
  } catch (error) {
400
- console.error(`
401
- === \u8C03\u8BD5\u9519\u8BEF\uFF1AcheckUsersInGroupDebug ===`);
402
- console.error(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
403
- console.error(`=== \u8C03\u8BD5\u7ED3\u675F ===
404
- `);
405
381
  ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
406
382
  return false;
407
383
  }
@@ -574,7 +550,7 @@ function apply(ctx, cfg) {
574
550
  ctx.command("cave [id:number]").action(
575
551
  async ({ session }, id) => await getCave(ctx, session, cfg, id)
576
552
  );
577
- ctx.command("cave.echo [...userIds:string]").action(
553
+ ctx.command("cave.echo [...userIds:number]").action(
578
554
  async ({ session }, ...userIds) => await addCave(ctx, session, cfg, userIds)
579
555
  );
580
556
  ctx.command("cave.wipe <id:number>").action(
@@ -584,7 +560,7 @@ function apply(ctx, cfg) {
584
560
  ctx.command("cave.trace").action(
585
561
  async ({ session }) => await getCaveListByOriginUser(ctx, session)
586
562
  );
587
- ctx.command("cave.bind <id:number> <...userIds:string>", { authority: 4 }).action(
563
+ ctx.command("cave.bind <id:number> <...userIds:number>", { authority: 4 }).action(
588
564
  async ({ session }, id, ...userIds) => await bindUsersToCave(ctx, session, id, userIds)
589
565
  );
590
566
  }
@@ -701,8 +677,9 @@ async function addCave(ctx, session, cfg, userIds) {
701
677
  }
702
678
  const { userId, channelId, quote } = session;
703
679
  const messageId = quote.id;
680
+ const userIdsStr = userIds.map((id) => id.toString());
704
681
  if (userIds && userIds.length > 0) {
705
- const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
682
+ const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIdsStr);
706
683
  if (!isAllUsersInGroup) {
707
684
  return session.text(".userNotInGroup");
708
685
  }
@@ -745,7 +722,7 @@ async function addCave(ctx, session, cfg, userIds) {
745
722
  originUserId: quote.user.id,
746
723
  type,
747
724
  content,
748
- relatedUsers: userIds || []
725
+ relatedUsers: userIdsStr || []
749
726
  });
750
727
  return session.text(".msgSaved", [result.id]);
751
728
  } catch (error) {
@@ -762,16 +739,17 @@ async function bindUsersToCave(ctx, session, id, userIds) {
762
739
  if (!userIds || userIds.length === 0) {
763
740
  return session.text(".noUserIdProvided");
764
741
  }
742
+ const userIdsStr = userIds.map((id2) => id2.toString());
765
743
  const caves = await ctx.database.get("echo_cave", id);
766
744
  if (caves.length === 0) {
767
745
  return session.text("echo-cave.general.noMsgWithId");
768
746
  }
769
- const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
747
+ const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIdsStr);
770
748
  if (!isAllUsersInGroup) {
771
749
  return session.text(".userNotInGroup");
772
750
  }
773
751
  await ctx.database.set("echo_cave", id, {
774
- relatedUsers: userIds
752
+ relatedUsers: userIdsStr
775
753
  });
776
754
  return session.text(".userBoundSuccess", [id]);
777
755
  }
@@ -4,7 +4,3 @@ export declare function getUserName(ctx: Context, session: Session, userId: stri
4
4
  * 检查用户是否属于指定群组
5
5
  */
6
6
  export declare function checkUsersInGroup(ctx: Context, session: Session, userIds: string[]): Promise<boolean>;
7
- /**
8
- * 检查用户是否属于指定群组(调试版本,输出详细信息)
9
- */
10
- export declare function checkUsersInGroupDebug(ctx: Context, session: Session, userIds: string[]): Promise<boolean>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.16.2",
4
+ "version": "1.16.4",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",