koishi-plugin-echo-cave 1.16.1 → 1.16.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/index.cjs CHANGED
@@ -372,12 +372,35 @@ async function getUserName(ctx, session, userId) {
372
372
  return userId;
373
373
  }
374
374
  }
375
- async function checkUsersInGroup(ctx, session, userIds) {
375
+ async function checkUsersInGroupDebug(ctx, session, userIds) {
376
376
  try {
377
- const groupMembers = await session.onebot.getGroupMemberList(session.channelId);
377
+ const channelId = session.channelId;
378
+ ctx.logger.info(`
379
+ === \u8C03\u8BD5\u4FE1\u606F\uFF1AcheckUsersInGroupDebug ===`);
380
+ ctx.logger.info(`channelId: ${channelId}`);
381
+ const groupMembers = await session.onebot.getGroupMemberList(channelId);
382
+ ctx.logger.info(`\u7FA4\u6210\u5458\u6570\u91CF\uFF1A${groupMembers.length}`);
383
+ ctx.logger.info(`\u7FA4\u6210\u5458ID\u5217\u8868\uFF1A${groupMembers.map((member) => member.user_id).join(", ")}`);
378
384
  const memberIds = groupMembers.map((member) => member.user_id.toString());
379
- return userIds.every((userId) => memberIds.includes(userId));
385
+ ctx.logger.info(`\u68C0\u67E5\u7684\u7528\u6237ID\uFF1A${userIds.join(", ")}`);
386
+ const usersNotHere = userIds.filter((userId) => !memberIds.includes(userId));
387
+ if (usersNotHere.length > 0) {
388
+ ctx.logger.info(`\u274C \u4E0D\u5728\u7FA4\u7EC4\u7684\u7528\u6237ID\uFF1A${usersNotHere.join(", ")}`);
389
+ ctx.logger.info(`=== \u8C03\u8BD5\u7ED3\u675F ===
390
+ `);
391
+ return false;
392
+ } else {
393
+ ctx.logger.info(`\u2705 \u6240\u6709\u7528\u6237\u90FD\u5728\u7FA4\u7EC4\u4E2D`);
394
+ ctx.logger.info(`=== \u8C03\u8BD5\u7ED3\u675F ===
395
+ `);
396
+ return true;
397
+ }
380
398
  } catch (error) {
399
+ ctx.logger.warn(`
400
+ === \u8C03\u8BD5\u9519\u8BEF\uFF1AcheckUsersInGroupDebug ===`);
401
+ ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
402
+ ctx.logger.warn(`=== \u8C03\u8BD5\u7ED3\u675F ===
403
+ `);
381
404
  ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
382
405
  return false;
383
406
  }
@@ -677,6 +700,12 @@ async function addCave(ctx, session, cfg, userIds) {
677
700
  }
678
701
  const { userId, channelId, quote } = session;
679
702
  const messageId = quote.id;
703
+ if (userIds && userIds.length > 0) {
704
+ const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
705
+ if (!isAllUsersInGroup) {
706
+ return session.text(".userNotInGroup");
707
+ }
708
+ }
680
709
  let content;
681
710
  let type;
682
711
  if (quote.elements[0].type === "forward") {
@@ -707,12 +736,6 @@ async function addCave(ctx, session, cfg, userIds) {
707
736
  return session.text(".existingMsg");
708
737
  }
709
738
  });
710
- if (userIds && userIds.length > 0) {
711
- const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIds);
712
- if (!isAllUsersInGroup) {
713
- return session.text(".userNotInGroup");
714
- }
715
- }
716
739
  try {
717
740
  const result = await ctx.database.create("echo_cave", {
718
741
  channelId,
@@ -742,7 +765,7 @@ async function bindUsersToCave(ctx, session, id, userIds) {
742
765
  if (caves.length === 0) {
743
766
  return session.text("echo-cave.general.noMsgWithId");
744
767
  }
745
- const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIds);
768
+ const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
746
769
  if (!isAllUsersInGroup) {
747
770
  return session.text(".userNotInGroup");
748
771
  }
@@ -4,3 +4,7 @@ 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.1",
4
+ "version": "1.16.3",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",