From 941b89a52333cd9915ed647799dfd8178c5954ae 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: Thu, 11 Jul 2024 12:28:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20uin=E8=BD=AC=E6=8D=A2=E4=BC=98=E5=8C=96?= =?UTF-8?q?&poke=E6=94=AF=E6=8C=81=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils/QQBasicInfo.ts | 2 +- src/core/src/apis/user.ts | 20 ++++++++- src/core/src/entities/msg.ts | 2 + src/onebot11/constructor.ts | 27 ++++++++---- src/onebot11/event/notice/OB11PokeEvent.ts | 18 ++++---- src/onebot11/main.ts | 49 +++++++++++----------- 6 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/common/utils/QQBasicInfo.ts b/src/common/utils/QQBasicInfo.ts index a90887f7..a9383668 100644 --- a/src/common/utils/QQBasicInfo.ts +++ b/src/common/utils/QQBasicInfo.ts @@ -69,7 +69,7 @@ export const qqPkgInfo: QQPkgInfo = JSON.parse(fs.readFileSync(pkgInfoPath).toSt // app_version: '3.2.9-24568', // qua: 'V1_LNX_NQ_3.2.9_24568_GW_B', -let _appid: string = '537226369'; // 默认为 Windows 平台的 appid +let _appid: string = '537231759'; // 默认为 Windows 平台的 appid if (systemPlatform === 'linux') { _appid = '537226441'; } diff --git a/src/core/src/apis/user.ts b/src/core/src/apis/user.ts index bb236742..0ed07e40 100644 --- a/src/core/src/apis/user.ts +++ b/src/core/src/apis/user.ts @@ -205,7 +205,25 @@ export class NTQQUserApi { 5000, [Uid] ); - return ret.uinInfo.get(Uid); + let uin = ret.uinInfo.get(Uid); + if (!uin) { + //从Buddy缓存获取Uin + Array.from(friends.values()).forEach((t) => { + if (t.uid == Uid) { + uin = t.uin; + } + }) + } + if (!uin) { + uin = (await NTQQUserApi.getUserDetailInfo(Uid)).uin; //从QQ Native 转换 + } + if (!uin) { + uin = (await NTQQFriendApi.getFriends(false)).find((t) => { t.uid == Uid })?.uin; //从QQ Native 缓存转换 + } + if (!uin) { + uin = (await NTQQFriendApi.getFriends(true)).find((t) => { t.uid == Uid })?.uin; //从QQ Native 非缓存转换 + } + return uin; } static async getUserDetailInfoByUin(Uin: string) { return NTEventDispatch.CallNoListenerEvent diff --git a/src/core/src/entities/msg.ts b/src/core/src/entities/msg.ts index 73572fa6..3c46cd71 100644 --- a/src/core/src/entities/msg.ts +++ b/src/core/src/entities/msg.ts @@ -30,6 +30,7 @@ export enum ElementType { VIDEO = 5, FACE = 6, REPLY = 7, + GreyTip = 8,//Poke别叫戳一搓了 官方名字拍一拍 戳一戳是另一个名字 ARK = 10, MFACE = 11, MARKDOWN = 14 @@ -289,6 +290,7 @@ export interface GrayTipElement { templId: string; }; jsonGrayTipElement: { + busiId?: number; jsonStr: string; }; } diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index 9ff08c66..ebde8469 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -43,6 +43,7 @@ import { deleteGroup, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } import { NTQQFileApi, NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis'; import { OB11GroupMsgEmojiLikeEvent } from '@/onebot11/event/notice/OB11MsgEmojiLikeEvent'; import { napCatCore } from '@/core'; +import { OB11GroupPokeEvent } from './event/notice/OB11PokeEvent'; export class OB11Constructor { @@ -162,7 +163,7 @@ export class OB11Constructor { message_data['type'] = 'image'; // message_data["data"]["file"] = element.picElement.sourcePath message_data['data']['file'] = element.picElement.fileName; - message_data['subType']= element.picElement.picSubType; + message_data['subType'] = element.picElement.picSubType; // message_data["data"]["path"] = element.picElement.sourcePath // let currentRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64" @@ -287,10 +288,11 @@ export class OB11Constructor { } static async GroupEvent(msg: RawMessage): Promise { + //log("group msg", msg); if (msg.chatType !== ChatType.group) { return; } - if (msg.senderUin) { + if (msg.senderUin && msg.senderUin !== '0') { const member = await getGroupMember(msg.peerUid, msg.senderUin); if (member && member.cardName !== msg.sendMemberName) { const newCardName = msg.sendMemberName || ''; @@ -299,7 +301,6 @@ export class OB11Constructor { return event; } } - // log("group msg", msg); for (const element of msg.elements) { const grayTipElement = element.grayTipElement; const groupElement = grayTipElement?.groupElement; @@ -369,11 +370,8 @@ export class OB11Constructor { busid: element.fileElement.fileBizId || 0 }); } - if (grayTipElement) { - const xmlElement = grayTipElement.xmlElement; - - if (xmlElement?.templId === '10382') { + if (grayTipElement.xmlElement?.templId === '10382') { // 表情回应消息 // "content": // " @@ -385,7 +383,7 @@ export class OB11Constructor { const emojiLikeData = new fastXmlParser.XMLParser({ ignoreAttributes: false, attributeNamePrefix: '' - }).parse(xmlElement.content); + }).parse(grayTipElement.xmlElement.content); logDebug('收到表情回应我的消息', emojiLikeData); try { const senderUin = emojiLikeData.gtip.qq.jp; @@ -422,6 +420,7 @@ export class OB11Constructor { } } } + //代码歧义 GrayTipElementSubType.MEMBER_NEW_TITLE else if (grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE) { const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr); /* @@ -448,6 +447,18 @@ export class OB11Constructor { } * */ + if (grayTipElement.jsonGrayTipElement.busiId == 1061) { + //判断业务类型 + //Poke事件 + let pokedetail: any[] = json.items; + //筛选item带有uid的元素 + pokedetail = pokedetail.filter(item => item.uid); + console.log("[NapCat] 群拍一拍 群:", pokedetail, parseInt(msg.peerUid), " ", await NTQQUserApi.getUinByUid(pokedetail[0].uid), "拍了拍", await NTQQUserApi.getUinByUid(pokedetail[1].uid)); + if (pokedetail.length == 2) { + return new OB11GroupPokeEvent(parseInt(msg.peerUid), parseInt((await NTQQUserApi.getUinByUid(pokedetail[0].uid))!), parseInt((await NTQQUserApi.getUinByUid(pokedetail[1].uid))!)); + } + } + //下面得改 上面也是错的grayTipElement.subElementType == GrayTipElementSubType.MEMBER_NEW_TITLE const memberUin = json.items[1].param[0]; const title = json.items[3].txt; logDebug('收到群成员新头衔消息', json); diff --git a/src/onebot11/event/notice/OB11PokeEvent.ts b/src/onebot11/event/notice/OB11PokeEvent.ts index ad954528..4df8fafa 100644 --- a/src/onebot11/event/notice/OB11PokeEvent.ts +++ b/src/onebot11/event/notice/OB11PokeEvent.ts @@ -2,29 +2,29 @@ import { OB11BaseNoticeEvent } from './OB11BaseNoticeEvent'; import { selfInfo } from '@/core/data'; import { OB11BaseEvent } from '../OB11BaseEvent'; -class OB11PokeEvent extends OB11BaseNoticeEvent{ +class OB11PokeEvent extends OB11BaseNoticeEvent { notice_type = 'notify'; sub_type = 'poke'; - target_id = parseInt(selfInfo.uin); - user_id: number; + target_id = 0; + user_id = 0; } -export class OB11FriendPokeEvent extends OB11PokeEvent{ +export class OB11FriendPokeEvent extends OB11PokeEvent { sender_id: number; - constructor(user_id: number) { + constructor(user_id: number, sender_id: number) { super(); this.user_id = user_id; - this.sender_id = user_id; + this.sender_id = sender_id; } } -export class OB11GroupPokeEvent extends OB11PokeEvent{ +export class OB11GroupPokeEvent extends OB11PokeEvent { group_id: number; - constructor(group_id: number, user_id: number=0) { + constructor(group_id: number, target_id: number = 0, user_id: number = 0,) { super(); this.group_id = group_id; - this.target_id = user_id; + this.target_id = target_id; this.user_id = user_id; } } diff --git a/src/onebot11/main.ts b/src/onebot11/main.ts index ea8da8f1..626bb8a8 100644 --- a/src/onebot11/main.ts +++ b/src/onebot11/main.ts @@ -124,30 +124,30 @@ export class NapCatOnebot11 { const subType1 = sysMsg.body[0].subType1; let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent; //console.log(peeruid); - if (MsgType == 528 && subType0 == 290 && hex.length < 250 && hex.endsWith('04')) { - // 防止上报两次 私聊戳一戳 - if (PokeCache.has(peeruid)) { - log('[私聊] 用户 ', peeruin, ' 对你戳一戳'); - pokeEvent = new OB11FriendPokeEvent(peeruin); - postOB11Event(pokeEvent); - } - PokeCache.set(peeruid, false); - setTimeout(() => { - PokeCache.delete(peeruid); - }, 1000); - } - if (MsgType == 732 && subType0 == 20 && hex.length < 150 && hex.endsWith('04')) { - // 防止上报两次 群聊戳一戳 - if (PokeCache.has(peeruid)) { - log('[群聊] 群组 ', peeruin, ' 戳一戳'); - pokeEvent = new OB11GroupPokeEvent(peeruin); - postOB11Event(pokeEvent); - } - PokeCache.set(peeruid, false); - setTimeout(() => { - PokeCache.delete(peeruid); - }, 1000); - } + // if (MsgType == 528 && subType0 == 290 && hex.length < 250 && hex.endsWith('04')) { + // // 防止上报两次 私聊戳一戳 + // if (PokeCache.has(peeruid)) { + // log('[私聊] 用户 ', peeruin, ' 对你戳一戳'); + // pokeEvent = new OB11FriendPokeEvent(peeruin); + // postOB11Event(pokeEvent); + // } + // PokeCache.set(peeruid, false); + // setTimeout(() => { + // PokeCache.delete(peeruid); + // }, 1000); + // } + // if (MsgType == 732 && subType0 == 20 && hex.length < 150 && hex.endsWith('04')) { + // // 防止上报两次 群聊戳一戳 + // if (PokeCache.has(peeruid)) { + // log('[群聊] 群组 ', peeruin, ' 戳一戳'); + // pokeEvent = new OB11GroupPokeEvent(peeruin); + // postOB11Event(pokeEvent); + // } + // PokeCache.set(peeruid, false); + // setTimeout(() => { + // PokeCache.delete(peeruid); + // }, 1000); + // } if (MsgType == 528 && subType0 == 349) { const sysDeviceMsg = DeviceData.fromBinary(Buffer.from(protobufData)); DeviceList = []; @@ -332,6 +332,7 @@ export class NapCatOnebot11 { postOB11Event(msg); // log("post msg", msg) }).catch(e => logError('constructMessage error: ', e)); + await OB11Constructor.GroupEvent(message); OB11Constructor.GroupEvent(message).then(groupEvent => { if (groupEvent) { // log("post group event", groupEvent);