koishi-plugin-echo-cave 1.16.3 → 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 +11 -32
- package/lib/onebot-helper.d.ts +0 -4
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -372,35 +372,12 @@ async function getUserName(ctx, session, userId) {
|
|
|
372
372
|
return userId;
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
async function
|
|
375
|
+
async function checkUsersInGroup(ctx, session, userIds) {
|
|
376
376
|
try {
|
|
377
|
-
const
|
|
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(", ")}`);
|
|
377
|
+
const groupMembers = await session.onebot.getGroupMemberList(session.channelId);
|
|
384
378
|
const memberIds = groupMembers.map((member) => member.user_id.toString());
|
|
385
|
-
|
|
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
|
-
}
|
|
379
|
+
return userIds.every((userId) => memberIds.includes(userId));
|
|
398
380
|
} 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
|
-
`);
|
|
404
381
|
ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
|
|
405
382
|
return false;
|
|
406
383
|
}
|
|
@@ -573,7 +550,7 @@ function apply(ctx, cfg) {
|
|
|
573
550
|
ctx.command("cave [id:number]").action(
|
|
574
551
|
async ({ session }, id) => await getCave(ctx, session, cfg, id)
|
|
575
552
|
);
|
|
576
|
-
ctx.command("cave.echo [...userIds:
|
|
553
|
+
ctx.command("cave.echo [...userIds:number]").action(
|
|
577
554
|
async ({ session }, ...userIds) => await addCave(ctx, session, cfg, userIds)
|
|
578
555
|
);
|
|
579
556
|
ctx.command("cave.wipe <id:number>").action(
|
|
@@ -583,7 +560,7 @@ function apply(ctx, cfg) {
|
|
|
583
560
|
ctx.command("cave.trace").action(
|
|
584
561
|
async ({ session }) => await getCaveListByOriginUser(ctx, session)
|
|
585
562
|
);
|
|
586
|
-
ctx.command("cave.bind <id:number> <...userIds:
|
|
563
|
+
ctx.command("cave.bind <id:number> <...userIds:number>", { authority: 4 }).action(
|
|
587
564
|
async ({ session }, id, ...userIds) => await bindUsersToCave(ctx, session, id, userIds)
|
|
588
565
|
);
|
|
589
566
|
}
|
|
@@ -700,8 +677,9 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
700
677
|
}
|
|
701
678
|
const { userId, channelId, quote } = session;
|
|
702
679
|
const messageId = quote.id;
|
|
680
|
+
const userIdsStr = userIds.map((id) => id.toString());
|
|
703
681
|
if (userIds && userIds.length > 0) {
|
|
704
|
-
const isAllUsersInGroup = await
|
|
682
|
+
const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIdsStr);
|
|
705
683
|
if (!isAllUsersInGroup) {
|
|
706
684
|
return session.text(".userNotInGroup");
|
|
707
685
|
}
|
|
@@ -744,7 +722,7 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
744
722
|
originUserId: quote.user.id,
|
|
745
723
|
type,
|
|
746
724
|
content,
|
|
747
|
-
relatedUsers:
|
|
725
|
+
relatedUsers: userIdsStr || []
|
|
748
726
|
});
|
|
749
727
|
return session.text(".msgSaved", [result.id]);
|
|
750
728
|
} catch (error) {
|
|
@@ -761,16 +739,17 @@ async function bindUsersToCave(ctx, session, id, userIds) {
|
|
|
761
739
|
if (!userIds || userIds.length === 0) {
|
|
762
740
|
return session.text(".noUserIdProvided");
|
|
763
741
|
}
|
|
742
|
+
const userIdsStr = userIds.map((id2) => id2.toString());
|
|
764
743
|
const caves = await ctx.database.get("echo_cave", id);
|
|
765
744
|
if (caves.length === 0) {
|
|
766
745
|
return session.text("echo-cave.general.noMsgWithId");
|
|
767
746
|
}
|
|
768
|
-
const isAllUsersInGroup = await
|
|
747
|
+
const isAllUsersInGroup = await checkUsersInGroup(ctx, session, userIdsStr);
|
|
769
748
|
if (!isAllUsersInGroup) {
|
|
770
749
|
return session.text(".userNotInGroup");
|
|
771
750
|
}
|
|
772
751
|
await ctx.database.set("echo_cave", id, {
|
|
773
|
-
relatedUsers:
|
|
752
|
+
relatedUsers: userIdsStr
|
|
774
753
|
});
|
|
775
754
|
return session.text(".userBoundSuccess", [id]);
|
|
776
755
|
}
|
package/lib/onebot-helper.d.ts
CHANGED
|
@@ -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>;
|