diff --git a/README.md b/README.md index d7461b67..809ec94d 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,16 @@ $env:FFMPEG_PATH="d:\ffmpeg\bin\ffmpeg.exe" 或者手机使用 VPN 等方式连接到服务器网络使其和服务器在同一网络 +### Windows 运行出现 sqlite3 不是 win32 程序 + +运行时出现`node_sqlite3.node is not a valid Win32 application` + +尝试自己用 npm 重新安装 sqlite3 + +```bash +npm uninstall sqlite3 +npm install sqlite3 +``` ### 其他问题 NapCat 是基于 QQ 22741 版本开发的,其他版本不敢保证是否会出现一些奇怪的问题,有问题可以尝试安装此版本的 QQ diff --git a/src/common/utils/db.ts b/src/common/utils/db.ts index a1ec01df..d44133f0 100644 --- a/src/common/utils/db.ts +++ b/src/common/utils/db.ts @@ -260,7 +260,7 @@ class DBUtil extends DBUtilBase { async updateFileCache(file: DBFile) { const stmt = this.db!.prepare('UPDATE files SET path = ?, url = ? WHERE uuid = ?'); return new Promise((resolve, reject) => { - stmt.run(file.path, file.url, function (err: any) { + stmt.run(file.path, file.url,file.uuid, function (err: any) { if (err) { log('db could not update file cache', err); reject(err); diff --git a/src/core.lib/MoeHook.node b/src/core.lib/MoeHook.node new file mode 100644 index 00000000..7d04ac4f Binary files /dev/null and b/src/core.lib/MoeHook.node differ diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index 5249a391..5755f3a7 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -39,7 +39,9 @@ import { OB11GroupCardEvent } from './event/notice/OB11GroupCardEvent'; import { OB11GroupDecreaseEvent } from './event/notice/OB11GroupDecreaseEvent'; import { ob11Config } from '@/onebot11/config'; import { deleteGroup, getFriend, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } from '@/common/data'; -import { NTQQGroupApi, NTQQUserApi } from '@/core/qqnt/apis'; +import { NTQQFileApi, NTQQGroupApi, NTQQUserApi } from '@/core/qqnt/apis'; +import { rkeyHook } from '@/core/qqnt/extends/rkey'; +import http from 'http'; export class OB11Constructor { @@ -143,9 +145,10 @@ export class OB11Constructor { const fileMd5 = element.picElement.md5HexStr; const fileUuid = element.picElement.fileUuid; // let currentRKey = config.imageRKey || "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64" - const currentRKey = 'CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64'; if (url) { if (url.startsWith('/download')) { + let rkey = rkeyHook.GetRkey(); + console.log('rkey', rkey); if (url.includes('&rkey=')) { // 正则提取rkey // const rkey = url.match(/&rkey=([^&]+)/)[1] @@ -157,14 +160,57 @@ export class OB11Constructor { // getConfigUtil().setConfig(config) // } // } - message_data['data']['url'] = IMAGE_HTTP_HOST + url; + message_data['data']['url'] = IMAGE_HTTP_HOST_NT + url; } else { - // 有可能会碰到appid为1406的,这个不能使用新的NT域名,并且需要把appid改为1407才可访问 - let host = IMAGE_HTTP_HOST_NT; - if (url.includes('appid=1406')) { - host = IMAGE_HTTP_HOST; + const getRkey = async () => { + await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, element.elementId, '', ''); + rkey = rkeyHook.GetRkey(); + }; + if (!rkey) { + // 下载一次图片获取rkey + try { + await getRkey(); + } catch (e) { + continue; + } } - message_data['data']['url'] = `${host}/download?appid=1407&fileid=${fileUuid}&rkey=${currentRKey}&spec=0`; + let imageUrl = IMAGE_HTTP_HOST_NT + url + `${rkey}`; + // 调用head请求获取图片rkey是否正常 + const checkUrl = new Promise((resolve, reject) => { + const options = { + method: 'HEAD', + host: new URL(imageUrl).host, + path: new URL(imageUrl).pathname + }; + const req = http.request(options, (res) => { + console.log(`STATUS: ${res.statusCode}`); + console.log(`HEADERS: ${JSON.stringify(res.headers)}`); + + if (res.statusCode == 200) { + console.log('The Image URL is accessible.'); + resolve('ok'); + } else { + reject('The Image URL is not accessible.'); + } + }); + + req.on('error', (e) => { + console.error(`problem with request: ${e.message}`); + reject(e.message); + }); + req.end(); + }); + try { + await checkUrl; + } catch (e) { + try { + await getRkey(); + imageUrl = IMAGE_HTTP_HOST_NT + url + `${rkey}`; + } catch (e) { + log('获取rkey失败', e); + } + } + message_data['data']['url'] = imageUrl; } } else { message_data['data']['url'] = IMAGE_HTTP_HOST + url; @@ -234,15 +280,13 @@ export class OB11Constructor { message_data['data']['data'] = element.arkElement.bytesData; } else if (element.faceElement) { const faceId = element.faceElement.faceIndex; - if (faceId === FaceIndex.dice){ + if (faceId === FaceIndex.dice) { message_data['type'] = OB11MessageDataType.dice; message_data['data']['result'] = element.faceElement.resultId; - } - else if (faceId === FaceIndex.RPS){ + } else if (faceId === FaceIndex.RPS) { message_data['type'] = OB11MessageDataType.RPS; message_data['data']['result'] = element.faceElement.resultId; - } - else{ + } else { message_data['type'] = OB11MessageDataType.face; message_data['data']['id'] = element.faceElement.faceIndex.toString(); } diff --git a/src/onebot11/index.ts b/src/onebot11/index.ts index c68651c8..0b6106cb 100644 --- a/src/onebot11/index.ts +++ b/src/onebot11/index.ts @@ -1,3 +1,4 @@ +import { rkeyHook } from '@/core/qqnt/extends/rkey'; import { napCatCore } from '@/core'; import { MsgListener } from '@/core/qqnt/listeners'; import { NapCatOnebot11 } from '@/onebot11/main'; @@ -38,6 +39,12 @@ checkVersion().then((remoteVersion: string) => { new NapCatOnebot11(); napCatCore.addLoginSuccessCallback(() => { console.log('login success'); + try{ + + console.log(rkeyHook.HookRkey()); + }catch (e) { + console.error(); + } postLoginStatus(); const msgListener = new MsgListener(); msgListener.onRecvMsg = (msg) => { diff --git a/vite.config.ts b/vite.config.ts index 1b5f396d..1e9e5aee 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,14 +11,14 @@ import os from 'node:os'; import fs from 'node:fs'; const external = ['silk-wasm', 'ws', 'express', 'uuid', 'fluent-ffmpeg', 'sqlite3', 'log4js', - 'qrcode-terminal']; + 'qrcode-terminal', 'MoeHook']; const nodeModules = [...builtinModules, builtinModules.map(m => `node:${m}`)].flat(); // let nodeModules = ["fs", "path", "events", "buffer", "url", "crypto", "fs/promise", "fsPromise", "os", "http", "net"] // nodeModules = [...nodeModules, ...nodeModules.map(m => `node:${m}`)] function genCpModule(module: string) { - return {src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false}; + return { src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false }; } const startScripts: string[] = ['./script/napcat.ps1', './script/napcat.bat', './script/napcat-utf8.bat', './script/napcat-utf8.ps1', './script/napcat-log.ps1', @@ -34,11 +34,12 @@ const baseConfigPlugin: PluginOption[] = [ cp({ targets: [ // ...external.map(genCpModule), - {src: './src/onebot11/onebot11.json', dest: 'dist/config/'}, - {src: './package.json', dest: 'dist'}, - {src: './README.md', dest: 'dist'}, + { src: './src/onebot11/onebot11.json', dest: 'dist/config/' }, + { src: './package.json', dest: 'dist' }, + { src: './README.md', dest: 'dist' }, + { src: './src/core.lib/MoeHook.node', dest: 'dist' }, ...(startScripts.map((startScript) => { - return {src: startScript, dest: 'dist'}; + return { src: startScript, dest: 'dist' }; })), ] }), @@ -74,7 +75,7 @@ const baseConfig = (mode: string = 'development') => defineConfig({ }, }); -export default defineConfig(({mode}): UserConfig => { +export default defineConfig(({ mode }): UserConfig => { if (mode === 'production') { return { ...baseConfig(mode),