From fbe101339dab2e4c60fa985d107b960655ae6202 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Tue, 28 May 2024 16:40:51 +0800 Subject: [PATCH] fix: #237 --- src/main/main.ts | 30 ++++++++++++++----- src/ntqqapi/api/user.ts | 5 +++- src/ntqqapi/types/notify.ts | 1 + .../event/request/OB11GroupRequest.ts | 1 + 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index a48542a..139cda0 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -349,32 +349,48 @@ function onLoad() { log('获取群通知的成员信息失败', notify, e.stack.toString()) } } - else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) { + else if ([GroupNotifyTypes.JOIN_REQUEST, GroupNotifyTypes.JOIN_REQUEST_BY_INVITED].includes(notify.type)) { log('有加群请求') let groupRequestEvent = new OB11GroupRequestEvent() groupRequestEvent.group_id = parseInt(notify.group.groupCode) - let requestQQ = '' - try { - requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin - } catch (e) { - log('获取加群人QQ号失败', e) + let requestQQ = uidMaps[notify.user1.uid] + if (!requestQQ) { + try { + requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin + } catch (e) { + log('获取加群人QQ号失败', e) + } } groupRequestEvent.user_id = parseInt(requestQQ) || 0 groupRequestEvent.sub_type = 'add' groupRequestEvent.comment = notify.postscript groupRequestEvent.flag = notify.seq + if (notify.type == GroupNotifyTypes.JOIN_REQUEST_BY_INVITED) { + // groupRequestEvent.sub_type = 'invite' + let invitorQQ = uidMaps[notify.user2.uid] + if (!invitorQQ) { + try { + let invitor = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid)) + groupRequestEvent.invitor_id = parseInt(invitor.uin) + } catch (e) { + groupRequestEvent.invitor_id = 0 + log('获取邀请人QQ号失败', e) + } + } + } postOb11Event(groupRequestEvent) } else if (notify.type == GroupNotifyTypes.INVITE_ME) { log('收到邀请我加群通知') let groupInviteEvent = new OB11GroupRequestEvent() groupInviteEvent.group_id = parseInt(notify.group.groupCode) - let user_id = (await getFriend(notify.user2.uid))?.uin + let user_id = uidMaps[notify.user2.uid] if (!user_id) { user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin } groupInviteEvent.user_id = parseInt(user_id) groupInviteEvent.sub_type = 'invite' + // groupInviteEvent.invitor_id = parseInt(user_id) groupInviteEvent.flag = notify.seq postOb11Event(groupInviteEvent) } diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index bf4bf5e..09a6202 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -47,9 +47,12 @@ export class NTQQUserApi { return result.profiles.get(uid) } - static async getUserDetailInfo(uid: string, getLevel = false) { + static async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) { // this.getUserInfo(uid); let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO + if (!withBizInfo) { + methodName = NTQQApiMethod.USER_DETAIL_INFO + } const fetchInfo = async () => { const result = await callNTQQApi<{ info: User }>({ methodName, diff --git a/src/ntqqapi/types/notify.ts b/src/ntqqapi/types/notify.ts index b578c28..cf91bc3 100644 --- a/src/ntqqapi/types/notify.ts +++ b/src/ntqqapi/types/notify.ts @@ -1,6 +1,7 @@ export enum GroupNotifyTypes { INVITE_ME = 1, INVITED_JOIN = 4, // 有人接受了邀请入群 + JOIN_REQUEST_BY_INVITED = 5, // 有人邀请了别人入群 JOIN_REQUEST = 7, ADMIN_SET = 8, KICK_MEMBER = 9, diff --git a/src/onebot11/event/request/OB11GroupRequest.ts b/src/onebot11/event/request/OB11GroupRequest.ts index 07cd652..2f27f02 100644 --- a/src/onebot11/event/request/OB11GroupRequest.ts +++ b/src/onebot11/event/request/OB11GroupRequest.ts @@ -5,6 +5,7 @@ export class OB11GroupRequestEvent extends OB11GroupNoticeEvent { post_type = EventType.REQUEST request_type: 'group' = 'group' sub_type: 'add' | 'invite' = 'add' + invitor_id: number | undefined = undefined comment: string flag: string }