feat: sysMessage oldProto adapter

This commit is contained in:
pk5ls20 2024-11-13 17:44:12 +08:00
parent 75866b435e
commit f7f7e09cab
No known key found for this signature in database
GPG Key ID: 6370ED7A169F493A
3 changed files with 74 additions and 26 deletions

View File

@ -1,36 +1,36 @@
// TODO: further refactor in NapCat.Packet v2 // TODO: further refactor in NapCat.Packet v2
import { NapProtoMsg, ProtoField, ScalarType } from "@napneko/nap-proto-core"; import { NapProtoMsg, ProtoField, ScalarType } from "@napneko/nap-proto-core";
export const LikeDetail = { const LikeDetail = {
txt: ProtoField(1, ScalarType.STRING), txt: ProtoField(1, ScalarType.STRING),
uin: ProtoField(3, ScalarType.INT64), uin: ProtoField(3, ScalarType.INT64),
nickname: ProtoField(5, ScalarType.STRING) nickname: ProtoField(5, ScalarType.STRING)
}; };
export const LikeMsg = { const LikeMsg = {
times: ProtoField(1, ScalarType.INT32), times: ProtoField(1, ScalarType.INT32),
time: ProtoField(2, ScalarType.INT32), time: ProtoField(2, ScalarType.INT32),
detail: ProtoField(3, () => LikeDetail) detail: ProtoField(3, () => LikeDetail)
}; };
export const ProfileLikeSubTip = { const ProfileLikeSubTip = {
msg: ProtoField(14, () => LikeMsg) msg: ProtoField(14, () => LikeMsg)
}; };
export const ProfileLikeTip = { const ProfileLikeTip = {
msgType: ProtoField(1, ScalarType.INT32), msgType: ProtoField(1, ScalarType.INT32),
subType: ProtoField(2, ScalarType.INT32), subType: ProtoField(2, ScalarType.INT32),
content: ProtoField(203, () => ProfileLikeSubTip) content: ProtoField(203, () => ProfileLikeSubTip)
}; };
export const SysMessageHeader = { const SysMessageHeader = {
PeerNumber: ProtoField(1, ScalarType.UINT32), PeerNumber: ProtoField(1, ScalarType.UINT32),
PeerString: ProtoField(2, ScalarType.STRING), PeerString: ProtoField(2, ScalarType.STRING),
Uin: ProtoField(5, ScalarType.UINT32), Uin: ProtoField(5, ScalarType.UINT32),
Uid: ProtoField(6, ScalarType.STRING, true) Uid: ProtoField(6, ScalarType.STRING, true)
}; };
export const SysMessageMsgSpec = { const SysMessageMsgSpec = {
msgType: ProtoField(1, ScalarType.UINT32), msgType: ProtoField(1, ScalarType.UINT32),
subType: ProtoField(2, ScalarType.UINT32), subType: ProtoField(2, ScalarType.UINT32),
subSubType: ProtoField(3, ScalarType.UINT32), subSubType: ProtoField(3, ScalarType.UINT32),
@ -40,11 +40,11 @@ export const SysMessageMsgSpec = {
other: ProtoField(13, ScalarType.UINT32) other: ProtoField(13, ScalarType.UINT32)
}; };
export const SysMessageBodyWrapper = { const SysMessageBodyWrapper = {
wrappedBody: ProtoField(2, ScalarType.BYTES) wrappedBody: ProtoField(2, ScalarType.BYTES)
}; };
export const SysMessage = { const SysMessage = {
header: ProtoField(1, () => SysMessageHeader, false, true), header: ProtoField(1, () => SysMessageHeader, false, true),
msgSpec: ProtoField(2, () => SysMessageMsgSpec, false, true), msgSpec: ProtoField(2, () => SysMessageMsgSpec, false, true),
bodyWrapper: ProtoField(3, () => SysMessageBodyWrapper) bodyWrapper: ProtoField(3, () => SysMessageBodyWrapper)

View File

@ -0,0 +1,49 @@
// TODO: further refactor in NapCat.Packet v2
import { NapProtoMsg, ProtoField, ScalarType } from "@napneko/nap-proto-core";
const BodyInner = {
msgType: ProtoField(1, ScalarType.UINT32, true),
subType: ProtoField(2, ScalarType.UINT32, true)
};
const NoifyData = {
skip: ProtoField(1, ScalarType.BYTES, true),
innerData: ProtoField(2, ScalarType.BYTES, true)
};
const MsgHead = {
bodyInner: ProtoField(2, () => BodyInner, true),
noifyData: ProtoField(3, () => NoifyData, true)
};
const Message = {
msgHead: ProtoField(1, () => MsgHead)
};
const SubDetail = {
msgSeq: ProtoField(1, ScalarType.UINT32),
msgTime: ProtoField(2, ScalarType.UINT32),
senderUid: ProtoField(6, ScalarType.STRING)
};
const RecallDetails = {
operatorUid: ProtoField(1, ScalarType.STRING),
subDetail: ProtoField(3, () => SubDetail)
};
const RecallGroup = {
type: ProtoField(1, ScalarType.INT32),
peerUid: ProtoField(4, ScalarType.UINT32),
recallDetails: ProtoField(11, () => RecallDetails),
grayTipsSeq: ProtoField(37, ScalarType.UINT32)
};
export function decodeMessage(buffer: Uint8Array) {
const msg = new NapProtoMsg(Message);
return msg.decode(buffer);
}
export function decodeRecallGroup(buffer: Uint8Array){
const msg = new NapProtoMsg(RecallGroup);
return msg.decode(buffer);
}

View File

@ -46,7 +46,7 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecal
import { LRUCache } from '@/common/lru-cache'; import { LRUCache } from '@/common/lru-cache';
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener'; import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
import { Native } from '@/native'; import { Native } from '@/native';
//import { decodeMessage, decodeRecallGroup } from '@/core/packet/proto/old/Message'; import { decodeMessage, decodeRecallGroup } from "@/core/helper/adaptSysMessageDecoder";
import { BotOfflineEvent } from './event/notice/BotOfflineEvent'; import { BotOfflineEvent } from './event/notice/BotOfflineEvent';
//OneBot实现类 //OneBot实现类
@ -83,25 +83,24 @@ export class NapCatOneBot11Adapter {
async registerNative(core: NapCatCore, context: InstanceContext) { async registerNative(core: NapCatCore, context: InstanceContext) {
try { try {
this.nativeCore = new Native(context.pathWrapper.binaryPath); this.nativeCore = new Native(context.pathWrapper.binaryPath);
// if (!this.nativeCore.inited) throw new Error('Native Not Init'); if (!this.nativeCore.inited) throw new Error('Native Not Init');
this.nativeCore.registerRecallCallback(async (hex: string) => { this.nativeCore.registerRecallCallback(async (hex: string) => {
try { try {
// TODO: refactor! const data = decodeMessage(Buffer.from(hex, 'hex'));
// const data = decodeMessage(Buffer.from(hex, 'hex')); //data.MsgHead.BodyInner.MsgType SubType
// //data.MsgHead.BodyInner.MsgType SubType const bodyInner = data.msgHead?.bodyInner;
// const bodyInner = data.msgHead?.bodyInner; //context.logger.log("[appNative] Parse MsgType:" + bodyInner.msgType + " / SubType:" + bodyInner.subType);
// //context.logger.log("[appNative] Parse MsgType:" + bodyInner.msgType + " / SubType:" + bodyInner.subType); if (bodyInner && bodyInner.msgType == 732 && bodyInner.subType == 17 && data?.msgHead?.noifyData?.innerData) {
// if (bodyInner && bodyInner.msgType == 732 && bodyInner.subType == 17) { const RecallData = Buffer.from(data?.msgHead?.noifyData?.innerData);
// const RecallData = Buffer.from(data.msgHead.noifyData.innerData); //跳过 4字节 群号 + 不知道的1字节 +2字节 长度
// //跳过 4字节 群号 + 不知道的1字节 +2字节 长度 const uid = RecallData.readUint32BE();
// const uid = RecallData.readUint32BE(); const buffer = Buffer.from(RecallData.toString('hex').slice(14), 'hex');
// const buffer = Buffer.from(RecallData.toString('hex').slice(14), 'hex'); const seq: number = decodeRecallGroup(buffer).recallDetails.subDetail.msgSeq;
// const seq: number = decodeRecallGroup(buffer).recallDetails.subDetail.msgSeq; const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() };
// const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() }; context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq);
// context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq); const msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString());
// const msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString()); this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]);
// this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]); }
// }
} catch (error: any) { } catch (error: any) {
context.logger.logWarn("[Native] Error:", (error as Error).message, ' HEX:', hex); context.logger.logWarn("[Native] Error:", (error as Error).message, ' HEX:', hex);
} }