refactor: packet x1

This commit is contained in:
pk5ls20
2024-11-12 04:02:19 +08:00
parent af29c17814
commit 7fd94a03b7
105 changed files with 2286 additions and 1962 deletions

View File

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