diff --git a/manifest.json b/manifest.json index c37e147..0d2fa92 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "manifest_version": 4, "type": "extension", - "name": "LLOneBot v3.26.2", + "name": "LLOneBot v3.26.3", "slug": "LLOneBot", "description": "使你的NTQQ支持OneBot11协议进行QQ机器人开发, 不支持商店在线更新", - "version": "3.26.2", + "version": "3.26.3", "icon": "./icon.jpg", "authors": [ { diff --git a/src/common/utils/QQBasicInfo.ts b/src/common/utils/QQBasicInfo.ts index 9f49536..29c0ceb 100644 --- a/src/common/utils/QQBasicInfo.ts +++ b/src/common/utils/QQBasicInfo.ts @@ -3,26 +3,34 @@ import fs from 'node:fs' import os from 'node:os' import { systemPlatform } from './system' -export const exePath = process.execPath; +export const exePath = process.execPath -export const pkgInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'package.json'); -let configVersionInfoPath; +function getPKGPath() { + let p = path.join(path.dirname(exePath), 'resources', 'app', 'package.json') + if (systemPlatform === 'darwin') { + p = path.join(path.dirname(path.dirname(exePath)), 'Resources', 'app', 'package.json') + } + return p +} +export const pkgInfoPath = getPKGPath() +let configVersionInfoPath: string if (os.platform() !== 'linux') { - configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); -} else { - const userPath = os.homedir(); - const appDataPath = path.resolve(userPath, './.config/QQ'); - configVersionInfoPath = path.resolve(appDataPath, './versions/config.json'); + configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json') +} +else { + const userPath = os.homedir() + const appDataPath = path.resolve(userPath, './.config/QQ') + configVersionInfoPath = path.resolve(appDataPath, './versions/config.json') } if (typeof configVersionInfoPath !== 'string') { - throw new Error('Something went wrong when load QQ info path'); + throw new Error('Something went wrong when load QQ info path') } -export { configVersionInfoPath }; +export { configVersionInfoPath } type QQPkgInfo = { version: string; @@ -43,21 +51,21 @@ let _qqVersionConfigInfo: QQVersionConfigInfo = { 'curVersion': '9.9.9-23361', 'prevVersion': '', 'onErrorVersions': [], - 'buildId': '23361' -}; + 'buildId': '23361', +} if (fs.existsSync(configVersionInfoPath)) { try { - const _ =JSON.parse(fs.readFileSync(configVersionInfoPath).toString()); - _qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _); + const _ = JSON.parse(fs.readFileSync(configVersionInfoPath).toString()) + _qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _) } catch (e) { - console.error('Load QQ version config info failed, Use default version', e); + console.error('Load QQ version config info failed, Use default version', e) } } -export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo; +export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo -export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath); +export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath) // platform_type: 3, // app_type: 4, // app_version: '9.9.9-23159', @@ -66,10 +74,10 @@ export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath); // platVer: '10.0.26100', // clientVer: '9.9.9-23159', -let _appid: string = '537213803'; // 默认为 Windows 平台的 appid +let _appid: string = '537213803' // 默认为 Windows 平台的 appid if (systemPlatform === 'linux') { - _appid = '537213827'; + _appid = '537213827' } // todo: mac 平台的 appid -export const appid = _appid; +export const appid = _appid export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106' \ No newline at end of file diff --git a/src/main/main.ts b/src/main/main.ts index 0b4108d..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) } @@ -421,7 +437,13 @@ function onLoad() { } }) startReceiveHook().then() - NTQQGroupApi.getGroups(true).then() + NTQQGroupApi.getGroups(true).then(groups=> { + for (let group of groups) { + } + } + ).catch(log) + NTQQGroupApi.activateMemberInfoChange().then().catch(log) + NTQQGroupApi.activateMemberListChange().then().catch(log) const config = getConfigUtil().getConfig() if (config.ob11.enableHttp) { ob11HTTPServer.start(config.ob11.httpPort) diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index 9618770..cbc4803 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -7,6 +7,33 @@ import { log } from '../../common/utils/log' import { NTQQWindowApi, NTQQWindows } from './window' export class NTQQGroupApi { + + static async activateMemberListChange(){ + return await callNTQQApi({ + methodName: NTQQApiMethod.ACTIVATE_MEMBER_LIST_CHANGE, + classNameIsRegister: true, + args: [], + }) + } + static async activateMemberInfoChange(){ + return await callNTQQApi({ + methodName: NTQQApiMethod.ACTIVATE_MEMBER_INFO_CHANGE, + classNameIsRegister: true, + args: [], + }) + } + static async getGroupAllInfo(groupCode: string, source: number=4){ + return await callNTQQApi({ + methodName: NTQQApiMethod.GET_GROUP_ALL_INFO, + args: [ + { + groupCode, + source + }, + null, + ], + }) + } static async getGroups(forced = false) { let cbCmd = ReceiveCmdS.GROUPS if (process.platform != 'win32') { @@ -58,6 +85,19 @@ export class NTQQGroupApi { return [] } } + static async getGroupMembersInfo(groupCode: string, uids: string[], forceUpdate: boolean=false) { + return await callNTQQApi({ + methodName: NTQQApiMethod.GROUP_MEMBERS_INFO, + args: [ + { + forceUpdate, + groupCode, + uids + }, + null, + ], + }) + } static async getGroupNotifies() { // 获取管理员变更 // 加群通知,退出通知,需要管理员权限 @@ -158,7 +198,8 @@ export class NTQQGroupApi { }) } static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) { - return await callNTQQApi({ + NTQQGroupApi.activateMemberListChange().then().catch(log) + const res = await callNTQQApi({ methodName: NTQQApiMethod.SET_MEMBER_CARD, args: [ { @@ -169,6 +210,8 @@ export class NTQQGroupApi { null, ], }) + NTQQGroupApi.getGroupMembersInfo(groupQQ, [memberUid], true).then().catch(log) + return res; } static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) { return await callNTQQApi({ diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index 0b9f76b..a91a8dd 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -29,7 +29,8 @@ async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 100 await sleep(500) checkLastSendUsingTime += 500 return await waitLastSend() - } else { + } + else { return } } @@ -48,7 +49,8 @@ async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 100 if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) { return sentMessage } - } else { + } + else { return sentMessage } // log(`给${peerUid}发送消息成功`) @@ -60,10 +62,28 @@ async function sendWaiter(peer: Peer, waitComplete = true, timeout: number = 100 await sleep(500) return await checkSendComplete() } - return checkSendComplete(); + return checkSendComplete() } export class NTQQMsgApi { + static enterOrExitAIO(peer: Peer, enter: boolean) { + return callNTQQApi({ + methodName: NTQQApiMethod.ENTER_OR_EXIT_AIO, + args: [ + { + "info_list": [ + { + peer, + "option": enter ? 1 : 2 + } + ] + }, + { + "send": true + }, + ], + }) + } static async setEmojiLike(peer: Peer, msgSeq: string, emojiId: string, set: boolean = true) { // nt_qq//global//nt_data//Emoji//emoji-resource//sysface_res/apng/ 下可以看到所有QQ表情预览 // nt_qq\global\nt_data\Emoji\emoji-resource\face_config.json 里面有所有表情的id, 自带表情id是QSid, 标准emoji表情id是QCid @@ -83,6 +103,7 @@ export class NTQQMsgApi { ], }) } + static async getMultiMsg(peer: Peer, rootMsgId: string, parentMsgId: string) { return await callNTQQApi({ methodName: NTQQApiMethod.GET_MULTI_MSG, @@ -97,6 +118,20 @@ export class NTQQMsgApi { }) } + static async getMsgBoxInfo(peer: Peer) { + return await callNTQQApi({ + methodName: NTQQApiMethod.GET_MSG_BOX_INFO, + args: [ + { + contacts: [ + peer + ], + }, + null, + ], + }) + } + static async activateChat(peer: Peer) { // await this.fetchRecentContact(); // await sleep(500); @@ -105,6 +140,7 @@ export class NTQQMsgApi { args: [{ peer, cnt: 20 }, null], }) } + static async activateChatAndGetHistory(peer: Peer) { // await this.fetchRecentContact(); // await sleep(500); @@ -114,6 +150,7 @@ export class NTQQMsgApi { args: [{ peer, cnt: 20 }, null], }) } + static async getMsgHistory(peer: Peer, msgId: string, count: number) { // 消息时间从旧到新 return await callNTQQApi({ @@ -129,6 +166,7 @@ export class NTQQMsgApi { ], }) } + static async fetchRecentContact() { await callNTQQApi({ methodName: NTQQApiMethod.RECENT_CONTACT, @@ -164,7 +202,7 @@ export class NTQQMsgApi { } static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) { - const waiter = sendWaiter(peer, waitComplete, timeout); + const waiter = sendWaiter(peer, waitComplete, timeout) callNTQQApi({ methodName: NTQQApiMethod.SEND_MSG, args: [ @@ -177,11 +215,11 @@ export class NTQQMsgApi { null, ], }).then() - return await waiter; + return await waiter } static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) { - const waiter = sendWaiter(destPeer, true, 10000); + const waiter = sendWaiter(destPeer, true, 10000) callNTQQApi({ methodName: NTQQApiMethod.FORWARD_MSG, args: [ @@ -195,7 +233,7 @@ export class NTQQMsgApi { null, ], }).then().catch(log) - return await waiter; + return await waiter } static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) { diff --git a/src/ntqqapi/api/user.ts b/src/ntqqapi/api/user.ts index cb23f36..0aab61b 100644 --- a/src/ntqqapi/api/user.ts +++ b/src/ntqqapi/api/user.ts @@ -48,9 +48,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/ntcall.ts b/src/ntqqapi/ntcall.ts index a76dca6..0177765 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -27,13 +27,17 @@ export enum NTQQApiMethod { HISTORY_MSG = 'nodeIKernelMsgService/getMsgsIncludeSelf', GET_MULTI_MSG = 'nodeIKernelMsgService/getMultiMsg', DELETE_ACTIVE_CHAT = 'nodeIKernelMsgService/deleteActiveChatByUid', + ENTER_OR_EXIT_AIO = 'nodeIKernelMsgService/enterOrExitAio', LIKE_FRIEND = 'nodeIKernelProfileLikeService/setBuddyProfileLike', SELF_INFO = 'fetchAuthData', FRIENDS = 'nodeIKernelBuddyService/getBuddyList', + GROUPS = 'nodeIKernelGroupService/getGroupList', GROUP_MEMBER_SCENE = 'nodeIKernelGroupService/createMemberListScene', GROUP_MEMBERS = 'nodeIKernelGroupService/getNextMemberList', + GROUP_MEMBERS_INFO = 'nodeIKernelGroupService/getMemberInfo', + USER_INFO = 'nodeIKernelProfileService/getUserSimpleInfo', USER_DETAIL_INFO = 'nodeIKernelProfileService/getUserDetailInfo', USER_DETAIL_INFO_WITH_BIZ_INFO = 'nodeIKernelProfileService/getUserDetailInfoWithBizInfo', @@ -65,6 +69,10 @@ export enum NTQQApiMethod { PUBLISH_GROUP_BULLETIN = 'nodeIKernelGroupService/publishGroupBulletinBulletin', SET_GROUP_NAME = 'nodeIKernelGroupService/modifyGroupName', SET_GROUP_TITLE = 'nodeIKernelGroupService/modifyMemberSpecialTitle', + ACTIVATE_MEMBER_LIST_CHANGE = 'nodeIKernelGroupListener/onMemberListChange', + ACTIVATE_MEMBER_INFO_CHANGE = 'nodeIKernelGroupListener/onMemberInfoChange', + GET_MSG_BOX_INFO = 'nodeIKernelMsgService/getABatchOfContactMsgBoxInfo', + GET_GROUP_ALL_INFO = 'nodeIKernelGroupService/getGroupAllInfo', CACHE_SET_SILENCE = 'nodeIKernelStorageCleanService/setSilentScan', CACHE_ADD_SCANNED_PATH = 'nodeIKernelStorageCleanService/addCacheScanedPaths', 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 } diff --git a/src/version.ts b/src/version.ts index f7264db..956ad43 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = '3.26.2' +export const version = '3.26.3'