koishi-plugin-group-verification 1.0.37 → 1.0.38
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.js +19 -6
- package/package.json +1 -1
- package/src/index.ts +34 -6
package/lib/index.js
CHANGED
|
@@ -447,16 +447,29 @@ async function handleGuildMemberRequestEvent(ctx, session) {
|
|
|
447
447
|
logger.warn("黑名单检查失败", e);
|
|
448
448
|
}
|
|
449
449
|
{
|
|
450
|
+
const isId = /* @__PURE__ */ __name((s) => !s || s === userId, "isId");
|
|
450
451
|
let resolvedName;
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
452
|
+
const evUser = session.event?.user;
|
|
453
|
+
if (!isId(evUser?.name)) resolvedName = evUser.name;
|
|
454
|
+
else if (!isId(evUser?.nick)) resolvedName = evUser.nick;
|
|
455
|
+
if (!resolvedName) {
|
|
456
|
+
const author = session.author;
|
|
457
|
+
if (!isId(author?.name)) resolvedName = author.name;
|
|
458
|
+
else if (!isId(author?.nick)) resolvedName = author.nick;
|
|
459
|
+
}
|
|
460
|
+
if (!resolvedName && !isId(session.username)) {
|
|
457
461
|
resolvedName = session.username;
|
|
458
462
|
}
|
|
463
|
+
if (!resolvedName) {
|
|
464
|
+
try {
|
|
465
|
+
const userInfo = await session.bot.getUser(userId);
|
|
466
|
+
const n = userInfo?.name || userInfo?.nickname;
|
|
467
|
+
if (!isId(n)) resolvedName = n;
|
|
468
|
+
} catch (_) {
|
|
469
|
+
}
|
|
470
|
+
}
|
|
459
471
|
session.username = resolvedName || userId;
|
|
472
|
+
clogV(`昵称解析: userId=${userId} resolved="${session.username}" evUser=${JSON.stringify(evUser)} author=${JSON.stringify(session.author)}`);
|
|
460
473
|
}
|
|
461
474
|
const { isValid, matchedCount, requiredThreshold } = await verifyApplication(config, message, session);
|
|
462
475
|
clogV(`验证结果 guild=${guildId} user=${userId} msg="${message}" matched=${matchedCount} threshold=${requiredThreshold} valid=${isValid}`);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -609,17 +609,45 @@ export async function handleGuildMemberRequestEvent(ctx: Context, session: any)
|
|
|
609
609
|
logger.warn('黑名单检查失败', e);
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
-
// 解析用户昵称优先级:
|
|
612
|
+
// 解析用户昵称优先级:
|
|
613
|
+
// 1) event 原始数据(NapCat/OneBot 入群申请事件本身携带昵称)
|
|
614
|
+
// 2) session.author.name / session.author.nick
|
|
615
|
+
// 3) session.username(若非 userId)
|
|
616
|
+
// 4) getUser() API
|
|
617
|
+
// 5) 最终 fallback:userId
|
|
613
618
|
{
|
|
619
|
+
const isId = (s: string | undefined) => !s || s === userId
|
|
620
|
+
|
|
614
621
|
let resolvedName: string | undefined
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
if (!resolvedName
|
|
622
|
+
|
|
623
|
+
// 优先级1:event 原始数据
|
|
624
|
+
const evUser = (session.event as any)?.user
|
|
625
|
+
if (!isId(evUser?.name)) resolvedName = evUser.name
|
|
626
|
+
else if (!isId(evUser?.nick)) resolvedName = evUser.nick
|
|
627
|
+
|
|
628
|
+
// 优先级2:author 字段
|
|
629
|
+
if (!resolvedName) {
|
|
630
|
+
const author = session.author as any
|
|
631
|
+
if (!isId(author?.name)) resolvedName = author.name
|
|
632
|
+
else if (!isId(author?.nick)) resolvedName = author.nick
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// 优先级3:session.username
|
|
636
|
+
if (!resolvedName && !isId(session.username)) {
|
|
620
637
|
resolvedName = session.username
|
|
621
638
|
}
|
|
639
|
+
|
|
640
|
+
// 优先级4:API 拉取(get_stranger_info)
|
|
641
|
+
if (!resolvedName) {
|
|
642
|
+
try {
|
|
643
|
+
const userInfo = await session.bot.getUser(userId)
|
|
644
|
+
const n = (userInfo as any)?.name || (userInfo as any)?.nickname
|
|
645
|
+
if (!isId(n)) resolvedName = n
|
|
646
|
+
} catch (_) {}
|
|
647
|
+
}
|
|
648
|
+
|
|
622
649
|
session.username = resolvedName || userId
|
|
650
|
+
clogV(`昵称解析: userId=${userId} resolved="${session.username}" evUser=${JSON.stringify(evUser)} author=${JSON.stringify((session as any).author)}`)
|
|
623
651
|
}
|
|
624
652
|
|
|
625
653
|
const { isValid, matchedCount, requiredThreshold } = await verifyApplication(config, message, session);
|