koishi-plugin-echo-cave 1.16.1 → 1.16.2
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 +34 -10
- package/lib/onebot-helper.d.ts +4 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -372,12 +372,36 @@ async function getUserName(ctx, session, userId) {
|
|
|
372
372
|
return userId;
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
async function
|
|
375
|
+
async function checkUsersInGroupDebug(ctx, session, userIds) {
|
|
376
376
|
try {
|
|
377
|
-
const
|
|
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(", ")}`);
|
|
378
384
|
const memberIds = groupMembers.map((member) => member.user_id.toString());
|
|
379
|
-
|
|
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
|
+
}
|
|
380
399
|
} 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
|
+
`);
|
|
381
405
|
ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u5217\u8868\u5931\u8D25\uFF1A`, error);
|
|
382
406
|
return false;
|
|
383
407
|
}
|
|
@@ -677,6 +701,12 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
677
701
|
}
|
|
678
702
|
const { userId, channelId, quote } = session;
|
|
679
703
|
const messageId = quote.id;
|
|
704
|
+
if (userIds && userIds.length > 0) {
|
|
705
|
+
const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
|
|
706
|
+
if (!isAllUsersInGroup) {
|
|
707
|
+
return session.text(".userNotInGroup");
|
|
708
|
+
}
|
|
709
|
+
}
|
|
680
710
|
let content;
|
|
681
711
|
let type;
|
|
682
712
|
if (quote.elements[0].type === "forward") {
|
|
@@ -707,12 +737,6 @@ async function addCave(ctx, session, cfg, userIds) {
|
|
|
707
737
|
return session.text(".existingMsg");
|
|
708
738
|
}
|
|
709
739
|
});
|
|
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
740
|
try {
|
|
717
741
|
const result = await ctx.database.create("echo_cave", {
|
|
718
742
|
channelId,
|
|
@@ -742,7 +766,7 @@ async function bindUsersToCave(ctx, session, id, userIds) {
|
|
|
742
766
|
if (caves.length === 0) {
|
|
743
767
|
return session.text("echo-cave.general.noMsgWithId");
|
|
744
768
|
}
|
|
745
|
-
const isAllUsersInGroup = await
|
|
769
|
+
const isAllUsersInGroup = await checkUsersInGroupDebug(ctx, session, userIds);
|
|
746
770
|
if (!isAllUsersInGroup) {
|
|
747
771
|
return session.text(".userNotInGroup");
|
|
748
772
|
}
|
package/lib/onebot-helper.d.ts
CHANGED
|
@@ -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>;
|