diff --git a/manifest.json b/manifest.json index d706622a..784b1472 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "NapCatQQ", "slug": "NapCat.Framework", "description": "高性能的 OneBot 11 协议实现", - "version": "2.6.19", + "version": "2.6.20", "icon": "./logo.png", "authors": [ { diff --git a/package.json b/package.json index 36de0227..e4785e2b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "napcat", "private": true, "type": "module", - "version": "2.6.19", + "version": "2.6.20", "scripts": { "build:framework": "vite build --mode framework", "build:shell": "vite build --mode shell", diff --git a/src/common/version.ts b/src/common/version.ts index 92712d1a..84cb5823 100644 --- a/src/common/version.ts +++ b/src/common/version.ts @@ -1 +1 @@ -export const napCatVersion = '2.6.19'; +export const napCatVersion = '2.6.20'; diff --git a/src/native/index.ts b/src/native/index.ts index 25135994..ef504380 100644 --- a/src/native/index.ts +++ b/src/native/index.ts @@ -7,21 +7,28 @@ export class Native { supportedPlatforms = ['win32']; MoeHooExport: any = { exports: {} }; recallHookEnabled: boolean = false; + inited = true; constructor(nodePath: string, platform: string = process.platform) { this.platform = platform; - 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)) { - dlopen(this.MoeHooExport, nativeNode, constants.dlopen.RTLD_LAZY); + try { + 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)) { + dlopen(this.MoeHooExport, nativeNode, constants.dlopen.RTLD_LAZY); + } + } catch (error) { + this.inited = false; } + } isSetReCallEnabled(): boolean { - return this.recallHookEnabled; + return this.recallHookEnabled && this.inited; } registerRecallCallback(callback: (hex: string) => any): void { try { + if (!this.inited) throw new Error('Native Not Init'); if (this.MoeHooExport.exports?.registMsgPush) { this.MoeHooExport.exports.registMsgPush(callback); this.recallHookEnabled = true; diff --git a/src/onebot/index.ts b/src/onebot/index.ts index 9c86c843..0c3a70ba 100644 --- a/src/onebot/index.ts +++ b/src/onebot/index.ts @@ -79,47 +79,34 @@ export class NapCatOneBot11Adapter { } async registerNative(core: NapCatCore, context: InstanceContext) { - this.nativeCore = new Native(context.pathWrapper.binaryPath); - this.nativeCore.registerRecallCallback(async (hex: string) => { - try { - 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); - if (bodyInner && 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 = 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()); - this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]); - // let ob11 = await this.apis.MsgApi.parseMessage(msgs.msgList[0], 'array') - // .catch(e => this.context.logger.logError.bind(this.context.logger)('处理消息失败', e)); - // if (ob11) { - // const { sendElements, deleteAfterSentFiles } = await this.apis.MsgApi.createSendElements(ob11.message as OB11MessageData[], peer); - // this.apis.MsgApi.sendMsgWithOb11UniqueId(peer, sendElements, deleteAfterSentFiles); - // } - - - // this.apis.MsgApi.sendMsg(peer, [{ - // elementType: 1, - // elementId: '', - // textElement: { - // content: "[Native] 群消息撤回 Peer: " + uid.toString() + " / MsgSeq:" + seq, - // atType: 0, - // atUid: '', - // atTinyId: '', - // atNtUid: '', - // }, - // }]); + try { + this.nativeCore = new Native(context.pathWrapper.binaryPath); + if (!this.nativeCore.inited) throw new Error('Native Not Init'); + this.nativeCore.registerRecallCallback(async (hex: string) => { + try { + 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); + if (bodyInner && 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 = 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()); + this.recallMsgCache.put(msgs.msgList[0].msgId, msgs.msgList[0]); + } + } catch (error: any) { + context.logger.logWarn("[Native] Error:", (error as Error).message, ' HEX:', hex); } - } 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() { const selfInfo = this.core.selfInfo; diff --git a/src/webui/ui/NapCat.ts b/src/webui/ui/NapCat.ts index 1a9a7e73..b3a27ecd 100644 --- a/src/webui/ui/NapCat.ts +++ b/src/webui/ui/NapCat.ts @@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) { SettingItem( 'Napcat', undefined, - SettingButton('V2.6.19', 'napcat-update-button', 'secondary'), + SettingButton('V2.6.20', 'napcat-update-button', 'secondary'), ), ]), SettingList([ diff --git a/static/assets/renderer.js b/static/assets/renderer.js index 7ff323de..45878c7f 100644 --- a/static/assets/renderer.js +++ b/static/assets/renderer.js @@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) { SettingItem( 'Napcat', void 0, - SettingButton("V2.6.19", "napcat-update-button", "secondary") + SettingButton("V2.6.20", "napcat-update-button", "secondary") ) ]), SettingList([