refactor: protobufjs给我似!

This commit is contained in:
手瓜一十雪
2024-09-29 20:06:11 +08:00
parent 78bac1dbd1
commit d332b199b5
6 changed files with 102 additions and 130 deletions

View File

@@ -45,7 +45,7 @@ import { OB11GroupRecallNoticeEvent } from '@/onebot/event/notice/OB11GroupRecal
import { LRUCache } from '@/common/lru-cache';
import { NodeIKernelRecentContactListener } from '@/core/listeners/NodeIKernelRecentContactListener';
import { Native } from '@/native';
import { Message, RecallGroup } from '@/core/proto/Message';
import { decodeMessage, decodeRecallGroup, Message, RecallGroup } from '@/core/proto/Message';
//OneBot实现类
export class NapCatOneBot11Adapter {
@@ -82,7 +82,7 @@ export class NapCatOneBot11Adapter {
this.nativeCore = new Native(context.pathWrapper.binaryPath);
this.nativeCore.registerRecallCallback(async (hex: string) => {
try {
let data = Message.decode(Buffer.from(hex, 'hex')) as any;
let data = decodeMessage(Buffer.from(hex, 'hex')) as any;
//data.MsgHead.BodyInner.MsgType SubType
let bodyInner = data.msgHead?.bodyInner;
//context.logger.log("[appNative] Parse MsgType:" + bodyInner.msgType + " / SubType:" + bodyInner.subType);
@@ -91,7 +91,7 @@ export class NapCatOneBot11Adapter {
//跳过 4字节 群号 + 不知道的1字节 +2字节 长度
let uid = RecallData.readUint32BE();
const buffer = Buffer.from(RecallData.toString('hex').slice(14), 'hex');
let seq: number = (RecallGroup.decode(buffer) as any).recallDetails.subDetail.msgSeq;
let seq: number = decodeRecallGroup(buffer).recallDetails.subDetail.msgSeq;
let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() };
context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq);
let msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString());