feat: uin转换优化&poke支持重写

This commit is contained in:
手瓜一十雪
2024-07-11 12:28:11 +08:00
parent a5f9e5f8c0
commit 941b89a523
6 changed files with 75 additions and 43 deletions

View File

@@ -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';
}

View File

@@ -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

View File

@@ -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;
};
}

View File

@@ -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<OB11GroupNoticeEvent | undefined> {
//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":
// "<gtip align=\"center\">
@@ -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);

View File

@@ -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;
}
}

View File

@@ -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);