This commit is contained in:
手瓜一十雪 2024-09-28 15:36:25 +08:00
parent 1ce8cd2100
commit 9bef9c85cf
3 changed files with 70 additions and 18 deletions

View File

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

23
src/core/proto/Message.ts Normal file
View File

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

View File

@ -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') {