From 9bef9c85cfc8af8e9095e93076388123aa00bd75 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: Sat, 28 Sep 2024 15:36:25 +0800 Subject: [PATCH] fix --- src/core/index.ts | 58 +++++++++++++++++++++++++++++++-------- src/core/proto/Message.ts | 23 ++++++++++++++++ src/shell/napcat.ts | 7 ----- 3 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 src/core/proto/Message.ts diff --git a/src/core/index.ts b/src/core/index.ts index 20dcad9e..0056fb59 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -24,11 +24,14 @@ import path from 'node:path'; import fs from 'node:fs'; import { hostname, systemName, systemVersion } from '@/common/system'; import { NTEventWrapper } from '@/common/event'; -import { DataSource, GroupMember, KickedOffLineInfo, SelfInfo, SelfStatusInfo } from '@/core/entities'; +import { ChatType, DataSource, GroupMember, KickedOffLineInfo, Peer, SelfInfo, SelfStatusInfo } from '@/core/entities'; import { NapCatConfigLoader } from '@/core/helper/config'; import os from 'node:os'; import { NodeIKernelGroupListener, NodeIKernelMsgListener, NodeIKernelProfileListener } from '@/core/listeners'; import { proxiedListenerOf } from '@/common/proxy-handler'; +import { Native } from '@/native'; +import { buffer } from 'stream/consumers'; +import { Message, MsgHead, RecallGroup } from './proto/Message'; export * from './wrapper'; export * from './entities'; @@ -77,6 +80,7 @@ export class NapCatCore { // 通过构造器递过去的 runtime info 应该尽量少 constructor(context: InstanceContext, selfInfo: SelfInfo) { + let appNative = new Native(context.pathWrapper.binaryPath); this.selfInfo = selfInfo; this.context = context; this.util = this.context.wrapper.NodeQQNTWrapperUtil; @@ -99,6 +103,38 @@ export class NapCatCore { if (!fs.existsSync(this.NapCatTempPath)) { fs.mkdirSync(this.NapCatTempPath, { recursive: true }); } + appNative.MoeHooExport.exports.registMsgPush(async (hex: string) => { + try { + let data = Message.decode(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); + if (bodyInner.msgType == 732 && bodyInner.subType == 17) { + let RecallData = Buffer.from(data.msgHead.noifyData.innerData); + //跳过 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).msgSeq; + let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() }; + context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq); + let msgs = await this.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString()) + console.log(JSON.stringify(msgs, null, 4)); + // this.apis.MsgApi.sendMsg(peer, [{ + // elementType: 1, + // elementId: '', + // textElement: { + // content: "[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq, + // atType: 0, + // atUid: '', + // atTinyId: '', + // atNtUid: '', + // }, + // }]); + } + } catch (error: any) { + //context.logger.logWarn("[appNative]", (error as Error).message); + } + }); this.initNapCatCoreListeners().then().catch(this.context.logger.logError.bind(this.context.logger)); this.context.logger.setFileLogEnabled( @@ -248,7 +284,7 @@ export class NapCatCore { } export async function genSessionConfig( - guid:string, + guid: string, QQVersionAppid: string, QQVersion: string, selfUin: string, @@ -260,15 +296,15 @@ export async function genSessionConfig( //os.platform() let systemPlatform = PlatformType.KWINDOWS; switch (os.platform()) { - case 'win32': - systemPlatform = PlatformType.KWINDOWS; - break; - case 'darwin': - systemPlatform = PlatformType.KMAC; - break; - case 'linux': - systemPlatform = PlatformType.KLINUX; - break; + case 'win32': + systemPlatform = PlatformType.KWINDOWS; + break; + case 'darwin': + systemPlatform = PlatformType.KMAC; + break; + case 'linux': + systemPlatform = PlatformType.KLINUX; + break; } return { selfUin, diff --git a/src/core/proto/Message.ts b/src/core/proto/Message.ts new file mode 100644 index 00000000..d4703a79 --- /dev/null +++ b/src/core/proto/Message.ts @@ -0,0 +1,23 @@ +import * as pb from 'protobufjs'; + + +export const BodyInner = new pb.Type("BodyInner") + .add(new pb.Field("msgType", 1, "uint32", "optional")) + .add(new pb.Field("subType", 2, "uint32", "optional")) + +export const NoifyData = new pb.Type("NoifyData") + .add(new pb.Field("skip", 1, "bytes", "optional")) + .add(new pb.Field("innerData", 2, "bytes", "optional")) + +export const MsgHead = new pb.Type("MsgHead") + .add(BodyInner) + .add(NoifyData) + .add(new pb.Field("bodyInner", 2, "BodyInner", "optional")) + .add(new pb.Field("noifyData", 3, "NoifyData", "optional")); + +export const Message = new pb.Type("Message") + .add(MsgHead) + .add(new pb.Field("msgHead", 1, "MsgHead")) + +export const RecallGroup = new pb.Type("RecallGroup") + .add(new pb.Field("msgSeq", 37, "uint32")) diff --git a/src/shell/napcat.ts b/src/shell/napcat.ts index 18e89b6e..68b2e053 100644 --- a/src/shell/napcat.ts +++ b/src/shell/napcat.ts @@ -29,7 +29,6 @@ import { InitWebUi } from '@/webui'; import { WebUiDataRuntime } from '@/webui/src/helper/Data'; import { napCatVersion } from '@/common/version'; import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener'; -import { Native } from '@/native'; program.option('-q, --qq [number]', 'QQ号').parse(process.argv); const cmdOptions = program.opts(); @@ -55,12 +54,6 @@ export async function NCoreInitShell() { const loginService = wrapper.NodeIKernelLoginService.get(); const session = wrapper.NodeIQQNTWrapperSession.create(); - - let appNative = new Native(pathWrapper.binaryPath); - appNative.MoeHooExport.exports.registMsgPush((...args: any[]) => { - console.log(args); - }); - console.log(appNative); // from get dataPath const [dataPath, dataPathGlobal] = (() => { if (os.platform() === 'darwin') {