From 4b319d15a7bf984a2be37acb209a2fc51ae53328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 6 Dec 2024 11:39:11 +0800 Subject: [PATCH] refactor: GetGroupInfo --- src/core/apis/group.ts | 14 ++ .../listeners/NodeIKernelGroupListener.ts | 4 +- src/core/services/NodeIKernelGroupService.ts | 2 +- src/core/services/NodeIKernelSearchService.ts | 2 +- src/core/types/group.ts | 155 +++++++++++++++++- src/onebot/action/group/GetGroupInfo.ts | 13 +- 6 files changed, 178 insertions(+), 12 deletions(-) diff --git a/src/core/apis/group.ts b/src/core/apis/group.ts index 60bf065aa..f412936e0 100644 --- a/src/core/apis/group.ts +++ b/src/core/apis/group.ts @@ -8,6 +8,7 @@ import { MemberExtSourceType, NapCatCore, GroupNotify, + GroupInfoSource, } from '@/core'; import { isNumeric, solveAsyncProblem } from '@/common/helper'; import { LimitedHashTable } from '@/common/message-unique'; @@ -24,6 +25,19 @@ export class NTQQGroupApi { this.core = core; } + async fetchGroupDetail(groupCode: string) { + let [, detailInfo] = await this.core.eventWrapper.callNormalEventV2( + 'NodeIKernelGroupService/getGroupDetailInfo', + 'NodeIKernelGroupListener/onGroupDetailInfoChange', + [groupCode, GroupInfoSource.KDATACARD], + (ret) => ret.result === 0, + (detailInfo) => detailInfo.groupCode === groupCode, + 1, + 5000 + ); + return detailInfo; + } + async initApi() { this.initCache().then().catch(e => this.context.logger.logError(e)); } diff --git a/src/core/listeners/NodeIKernelGroupListener.ts b/src/core/listeners/NodeIKernelGroupListener.ts index 962e24103..7873f3356 100644 --- a/src/core/listeners/NodeIKernelGroupListener.ts +++ b/src/core/listeners/NodeIKernelGroupListener.ts @@ -1,4 +1,4 @@ -import { DataSource, Group, GroupListUpdateType, GroupMember, GroupNotify, ShutUpGroupMember } from '@/core/types'; +import { DataSource, Group, GroupDetailInfo, GroupListUpdateType, GroupMember, GroupNotify, ShutUpGroupMember } from '@/core/types'; export class NodeIKernelGroupListener { onGroupListInited(listEmpty: boolean): any { } @@ -28,7 +28,7 @@ export class NodeIKernelGroupListener { onGroupConfMemberChange(...args: unknown[]): any { } - onGroupDetailInfoChange(...args: unknown[]): any { + onGroupDetailInfoChange(detailInfo: GroupDetailInfo): any { } onGroupExtListUpdate(...args: unknown[]): any { diff --git a/src/core/services/NodeIKernelGroupService.ts b/src/core/services/NodeIKernelGroupService.ts index 1b748883e..49d2f881b 100644 --- a/src/core/services/NodeIKernelGroupService.ts +++ b/src/core/services/NodeIKernelGroupService.ts @@ -149,7 +149,7 @@ export interface NodeIKernelGroupService { getGroupExtList(force: boolean): Promise; - getGroupDetailInfo(groupCode: string, groupInfoSource: GroupInfoSource): Promise; + getGroupDetailInfo(groupCode: string, groupInfoSource: GroupInfoSource): Promise; getMemberExtInfo(param: GroupExtParam): Promise;//req diff --git a/src/core/services/NodeIKernelSearchService.ts b/src/core/services/NodeIKernelSearchService.ts index dbdfb5732..5608d1cfe 100644 --- a/src/core/services/NodeIKernelSearchService.ts +++ b/src/core/services/NodeIKernelSearchService.ts @@ -16,7 +16,7 @@ export interface NodeIKernelSearchService { penetrate: string }): Promise;// needs 1 arguments - searchLocalInfo(keywords: string, unknown: number/*4*/): unknown; + searchLocalInfo(keywords: string, type: number/*4*/): unknown; cancelSearchLocalInfo(...args: any[]): unknown;// needs 3 arguments diff --git a/src/core/types/group.ts b/src/core/types/group.ts index 18a962764..862cb3a36 100644 --- a/src/core/types/group.ts +++ b/src/core/types/group.ts @@ -17,7 +17,160 @@ export enum GroupInfoSource { KRECENTCONTACT, KMOREPANEL } - +export interface GroupDetailInfo { + groupCode: string; + groupUin: string; + ownerUid: string; + ownerUin: string; + groupFlag: number; + groupFlagExt: number; + maxMemberNum: number; + memberNum: number; + groupOption: number; + classExt: number; + groupName: string; + fingerMemo: string; + groupQuestion: string; + certType: number; + richFingerMemo: string; + tagRecord: any[]; + shutUpAllTimestamp: number; + shutUpMeTimestamp: number; + groupTypeFlag: number; + privilegeFlag: number; + groupSecLevel: number; + groupFlagExt3: number; + isConfGroup: number; + isModifyConfGroupFace: number; + isModifyConfGroupName: number; + groupFlagExt4: number; + groupMemo: string; + cmdUinMsgSeq: number; + cmdUinJoinTime: number; + cmdUinUinFlag: number; + cmdUinMsgMask: number; + groupSecLevelInfo: number; + cmdUinPrivilege: number; + cmdUinFlagEx2: number; + appealDeadline: number; + remarkName: string; + isTop: boolean; + groupFace: number; + groupGeoInfo: { + ownerUid: string; + SetTime: number; + CityId: number; + Longitude: string; + Latitude: string; + GeoContent: string; + poiId: string; + }; + certificationText: string; + cmdUinRingtoneId: number; + longGroupName: string; + autoAgreeJoinGroupUserNumForConfGroup: number; + autoAgreeJoinGroupUserNumForNormalGroup: number; + cmdUinFlagExt3Grocery: number; + groupCardPrefix: { + introduction: string; + rptPrefix: any[]; + }; + groupExt: { + groupInfoExtSeq: number; + reserve: number; + luckyWordId: string; + lightCharNum: number; + luckyWord: string; + starId: number; + essentialMsgSwitch: number; + todoSeq: number; + blacklistExpireTime: number; + isLimitGroupRtc: number; + companyId: number; + hasGroupCustomPortrait: number; + bindGuildId: string; + groupOwnerId: { + memberUin: string; + memberUid: string; + memberQid: string; + }; + essentialMsgPrivilege: number; + msgEventSeq: string; + inviteRobotSwitch: number; + gangUpId: string; + qqMusicMedalSwitch: number; + showPlayTogetherSwitch: number; + groupFlagPro1: string; + groupBindGuildIds: { + guildIds: any[]; + }; + viewedMsgDisappearTime: string; + groupExtFlameData: { + switchState: number; + state: number; + dayNums: any[]; + version: number; + updateTime: string; + isDisplayDayNum: boolean; + }; + groupBindGuildSwitch: number; + groupAioBindGuildId: string; + groupExcludeGuildIds: { + guildIds: any[]; + }; + fullGroupExpansionSwitch: number; + fullGroupExpansionSeq: string; + inviteRobotMemberSwitch: number; + inviteRobotMemberExamine: number; + groupSquareSwitch: number; + }; + msgLimitFrequency: number; + hlGuildAppid: number; + hlGuildSubType: number; + isAllowRecallMsg: number; + confUin: string; + confMaxMsgSeq: number; + confToGroupTime: number; + groupSchoolInfo: { + location: string; + grade: number; + school: string; + }; + activeMemberNum: number; + groupGrade: number; + groupCreateTime: number; + subscriptionUin: string; + subscriptionUid: string; + noFingerOpenFlag: number; + noCodeFingerOpenFlag: number; + isGroupFreeze: number; + allianceId: string; + groupExtOnly: { + tribeId: number; + moneyForAddGroup: number; + }; + isAllowConfGroupMemberModifyGroupName: number; + isAllowConfGroupMemberNick: number; + isAllowConfGroupMemberAtAll: number; + groupClassText: string; + groupFreezeReason: number; + headPortraitSeq: number; + groupHeadPortrait: { + portraitCnt: number; + portraitInfo: any[]; + defaultId: number; + verifyingPortraitCnt: number; + verifyingPortraitInfo: any[]; + }; + cmdUinJoinMsgSeq: number; + cmdUinJoinRealMsgSeq: number; + groupAnswer: string; + groupAdminMaxNum: number; + inviteNoAuthNumLimit: string; + hlGuildOrgId: number; + isAllowHlGuildBinary: number; + localExitGroupReason: number; +} export interface GroupExt0xEF0InfoFilter { bindGuildId: number; blacklistExpireTime: number; diff --git a/src/onebot/action/group/GetGroupInfo.ts b/src/onebot/action/group/GetGroupInfo.ts index 6af134197..b4f7fda60 100644 --- a/src/onebot/action/group/GetGroupInfo.ts +++ b/src/onebot/action/group/GetGroupInfo.ts @@ -17,15 +17,14 @@ class GetGroupInfo extends OneBotAction { async _handle(payload: Payload) { const group = (await this.core.apis.GroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString()); if (!group) { - const data = await this.core.apis.GroupApi.searchGroup(payload.group_id.toString()); - if (!data) throw new Error('Group not found'); + const data = await this.core.apis.GroupApi.fetchGroupDetail(payload.group_id.toString()); return { - ...data.searchGroupInfo, + ...data, group_id: +payload.group_id, - group_name: data.searchGroupInfo.groupName, - member_count: data.searchGroupInfo.memberNum, - max_member_count: data.searchGroupInfo.maxMemberNum, - }; + group_name: data.groupName, + member_count: data.memberNum, + max_member_count: data.maxMemberNum, + } } return OB11Construct.group(group); }