release: v2.6.20

This commit is contained in:
手瓜一十雪 2024-09-30 17:05:02 +08:00
parent 410d6a85d7
commit da90245f7b
7 changed files with 46 additions and 52 deletions

View File

@ -4,7 +4,7 @@
"name": "NapCatQQ", "name": "NapCatQQ",
"slug": "NapCat.Framework", "slug": "NapCat.Framework",
"description": "高性能的 OneBot 11 协议实现", "description": "高性能的 OneBot 11 协议实现",
"version": "2.6.19", "version": "2.6.20",
"icon": "./logo.png", "icon": "./logo.png",
"authors": [ "authors": [
{ {

View File

@ -2,7 +2,7 @@
"name": "napcat", "name": "napcat",
"private": true, "private": true,
"type": "module", "type": "module",
"version": "2.6.19", "version": "2.6.20",
"scripts": { "scripts": {
"build:framework": "vite build --mode framework", "build:framework": "vite build --mode framework",
"build:shell": "vite build --mode shell", "build:shell": "vite build --mode shell",

View File

@ -1 +1 @@
export const napCatVersion = '2.6.19'; export const napCatVersion = '2.6.20';

View File

@ -7,21 +7,28 @@ export class Native {
supportedPlatforms = ['win32']; supportedPlatforms = ['win32'];
MoeHooExport: any = { exports: {} }; MoeHooExport: any = { exports: {} };
recallHookEnabled: boolean = false; recallHookEnabled: boolean = false;
inited = true;
constructor(nodePath: string, platform: string = process.platform) { constructor(nodePath: string, platform: string = process.platform) {
this.platform = platform; this.platform = platform;
if (!this.supportedPlatforms.includes(this.platform)) { try {
throw new Error(`Platform ${this.platform} is not supported`); if (!this.supportedPlatforms.includes(this.platform)) {
} throw new Error(`Platform ${this.platform} is not supported`);
let nativeNode = path.join(nodePath, './native/MoeHoo.win32.node'); }
if (fs.existsSync(nativeNode)) { let nativeNode = path.join(nodePath, './native/MoeHoo.win32.node');
dlopen(this.MoeHooExport, nativeNode, constants.dlopen.RTLD_LAZY); if (fs.existsSync(nativeNode)) {
dlopen(this.MoeHooExport, nativeNode, constants.dlopen.RTLD_LAZY);
}
} catch (error) {
this.inited = false;
} }
} }
isSetReCallEnabled(): boolean { isSetReCallEnabled(): boolean {
return this.recallHookEnabled; return this.recallHookEnabled && this.inited;
} }
registerRecallCallback(callback: (hex: string) => any): void { registerRecallCallback(callback: (hex: string) => any): void {
try { try {
if (!this.inited) throw new Error('Native Not Init');
if (this.MoeHooExport.exports?.registMsgPush) { if (this.MoeHooExport.exports?.registMsgPush) {
this.MoeHooExport.exports.registMsgPush(callback); this.MoeHooExport.exports.registMsgPush(callback);
this.recallHookEnabled = true; this.recallHookEnabled = true;

View File

@ -79,47 +79,34 @@ export class NapCatOneBot11Adapter {
} }
async registerNative(core: NapCatCore, context: InstanceContext) { async registerNative(core: NapCatCore, context: InstanceContext) {
this.nativeCore = new Native(context.pathWrapper.binaryPath); try {
this.nativeCore.registerRecallCallback(async (hex: string) => { this.nativeCore = new Native(context.pathWrapper.binaryPath);
try { if (!this.nativeCore.inited) throw new Error('Native Not Init');
let data = decodeMessage(Buffer.from(hex, 'hex')) as any; this.nativeCore.registerRecallCallback(async (hex: string) => {
//data.MsgHead.BodyInner.MsgType SubType try {
let bodyInner = data.msgHead?.bodyInner; let data = decodeMessage(Buffer.from(hex, 'hex')) as any;
//context.logger.log("[appNative] Parse MsgType:" + bodyInner.msgType + " / SubType:" + bodyInner.subType); //data.MsgHead.BodyInner.MsgType SubType
if (bodyInner && bodyInner.msgType == 732 && bodyInner.subType == 17) { let bodyInner = data.msgHead?.bodyInner;
let RecallData = Buffer.from(data.msgHead.noifyData.innerData); //context.logger.log("[appNative] Parse MsgType:" + bodyInner.msgType + " / SubType:" + bodyInner.subType);
//跳过 4字节 群号 + 不知道的1字节 +2字节 长度 if (bodyInner && bodyInner.msgType == 732 && bodyInner.subType == 17) {
let uid = RecallData.readUint32BE(); let RecallData = Buffer.from(data.msgHead.noifyData.innerData);
const buffer = Buffer.from(RecallData.toString('hex').slice(14), 'hex'); //跳过 4字节 群号 + 不知道的1字节 +2字节 长度
let seq: number = decodeRecallGroup(buffer).recallDetails.subDetail.msgSeq; let uid = RecallData.readUint32BE();
let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() }; const buffer = Buffer.from(RecallData.toString('hex').slice(14), 'hex');
context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq); let seq: number = decodeRecallGroup(buffer).recallDetails.subDetail.msgSeq;
let msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString()); let peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: uid.toString() };
this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]); context.logger.log("[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq);
// let ob11 = await this.apis.MsgApi.parseMessage(msgs.msgList[0], 'array') let msgs = await core.apis.MsgApi.queryMsgsWithFilterExWithSeq(peer, seq.toString());
// .catch(e => this.context.logger.logError.bind(this.context.logger)('处理消息失败', e)); this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]);
// if (ob11) { }
// const { sendElements, deleteAfterSentFiles } = await this.apis.MsgApi.createSendElements(ob11.message as OB11MessageData[], peer); } catch (error: any) {
// this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles); context.logger.logWarn("[Native] Error:", (error as Error).message, ' HEX:', hex);
// }
// 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("[Native] Error:", (error as Error).message, ' HEX:', hex); } catch (error) {
} context.logger.logWarn("[Native] Error:", (error as Error).message);
}); return;
}
} }
async InitOneBot() { async InitOneBot() {
const selfInfo = this.core.selfInfo; const selfInfo = this.core.selfInfo;

View File

@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
SettingItem( SettingItem(
'<span id="napcat-update-title">Napcat</span>', '<span id="napcat-update-title">Napcat</span>',
undefined, undefined,
SettingButton('V2.6.19', 'napcat-update-button', 'secondary'), SettingButton('V2.6.20', 'napcat-update-button', 'secondary'),
), ),
]), ]),
SettingList([ SettingList([

View File

@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
SettingItem( SettingItem(
'<span id="napcat-update-title">Napcat</span>', '<span id="napcat-update-title">Napcat</span>',
void 0, void 0,
SettingButton("V2.6.19", "napcat-update-button", "secondary") SettingButton("V2.6.20", "napcat-update-button", "secondary")
) )
]), ]),
SettingList([ SettingList([