diff --git a/electron.vite.config.ts b/electron.vite.config.ts index ac021ad..755888e 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -1,5 +1,6 @@ import cp from 'vite-plugin-cp' import './scripts/gen-version' +import path from 'node:path' const external = [ 'silk-wasm', @@ -34,6 +35,7 @@ let config = { }, resolve: { alias: { + '@': path.resolve(__dirname, './src'), './lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg', }, }, @@ -43,9 +45,9 @@ let config = { ...external.map(genCpModule), { src: './manifest.json', dest: 'dist' }, { src: './icon.jpg', dest: 'dist' }, - { src: './src/ntqqapi/external/crychic/crychic-win32-x64.node', dest: 'dist/main/' }, - { src: './src/ntqqapi/external/moehook/MoeHoo-win32-x64.node', dest: 'dist/main/' }, - { src: './src/ntqqapi/external/moehook/MoeHoo-linux-x64.node', dest: 'dist/main/' }, + { src: './src/ntqqapi/native/crychic/crychic-win32-x64.node', dest: 'dist/main/' }, + { src: './src/ntqqapi/native/moehook/MoeHoo-win32-x64.node', dest: 'dist/main/' }, + { src: './src/ntqqapi/native/moehook/MoeHoo-linux-x64.node', dest: 'dist/main/' }, ], }), ], diff --git a/src/common/utils/QQBasicInfo.ts b/src/common/utils/QQBasicInfo.ts new file mode 100644 index 0000000..f5da846 --- /dev/null +++ b/src/common/utils/QQBasicInfo.ts @@ -0,0 +1,73 @@ +import path from 'node:path' +import fs from 'node:fs' +import os from 'node:os' +import { systemPlatform } from './system' + +export const exePath = process.execPath; + +export const pkgInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'package.json'); +let configVersionInfoPath; + +if (os.platform() !== 'linux') { + configVersionInfoPath = path.join(path.dirname(exePath), 'resources', 'app', 'versions', 'config.json'); +} else { + const userPath = os.homedir(); + const appDataPath = path.resolve(userPath, './.config/QQ'); + configVersionInfoPath = path.resolve(appDataPath, './versions/config.json'); +} + +if (typeof configVersionInfoPath !== 'string') { + throw new Error('Something went wrong when load QQ info path'); +} + +export { configVersionInfoPath }; + +type QQPkgInfo = { + version: string; + buildVersion: string; + platform: string; + eleArch: string; +} +type QQVersionConfigInfo = { + baseVersion: string; + curVersion: string; + prevVersion: string; + onErrorVersions: Array; + buildId: string; +} + +let _qqVersionConfigInfo: QQVersionConfigInfo = { + 'baseVersion': '9.9.9-23361', + 'curVersion': '9.9.9-23361', + 'prevVersion': '', + 'onErrorVersions': [], + 'buildId': '23361' +}; + +if (fs.existsSync(configVersionInfoPath)) { + try { + const _ =JSON.parse(fs.readFileSync(configVersionInfoPath).toString()); + _qqVersionConfigInfo = Object.assign(_qqVersionConfigInfo, _); + } catch (e) { + console.error('Load QQ version config info failed, Use default version', e); + } +} + +export const qqVersionConfigInfo: QQVersionConfigInfo = _qqVersionConfigInfo; + +export const qqPkgInfo: QQPkgInfo = require(pkgInfoPath); +// platform_type: 3, +// app_type: 4, +// app_version: '9.9.9-23159', +// qua: 'V1_WIN_NQ_9.9.9_23159_GW_B', +// appid: '537213764', +// platVer: '10.0.26100', +// clientVer: '9.9.9-23159', + +let _appid: string = '537213803'; // 默认为 Windows 平台的 appid +if (systemPlatform === 'linux') { + _appid = '537213827'; +} +// todo: mac 平台的 appid +export const appid = _appid; +export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106' \ No newline at end of file diff --git a/src/common/utils/index.ts b/src/common/utils/index.ts index 156763e..fa95572 100644 --- a/src/common/utils/index.ts +++ b/src/common/utils/index.ts @@ -5,7 +5,7 @@ export * from './file' export * from './helper' export * from './log' export * from './qqlevel' -export * from './qqpkg' +export * from './QQBasicInfo' export * from './upgrade' export const DATA_DIR = global.LiteLoader.plugins['LLOneBot'].path.data export const TEMP_DIR = path.join(DATA_DIR, 'temp') @@ -16,3 +16,4 @@ if (!fs.existsSync(TEMP_DIR)) { export { getVideoInfo } from './video' export { checkFfmpeg } from './video' export { encodeSilk } from './audio' +export { isQQ998 } from './QQBasicInfo' \ No newline at end of file diff --git a/src/common/utils/qqpkg.ts b/src/common/utils/qqpkg.ts deleted file mode 100644 index 0043d53..0000000 --- a/src/common/utils/qqpkg.ts +++ /dev/null @@ -1,12 +0,0 @@ -import path from 'path' - -type QQPkgInfo = { - version: string - buildVersion: string - platform: string - eleArch: string -} - -export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, 'app/package.json')) - -export const isQQ998: boolean = qqPkgInfo.buildVersion >= '22106' diff --git a/src/common/utils/system.ts b/src/common/utils/system.ts new file mode 100644 index 0000000..77b5ea6 --- /dev/null +++ b/src/common/utils/system.ts @@ -0,0 +1,10 @@ +import os from 'node:os'; +import path from 'node:path'; + +export const systemPlatform = os.platform(); +export const cpuArch = os.arch(); +export const systemVersion = os.release(); +export const hostname = os.hostname(); +const homeDir = os.homedir(); +export const downloadsPath = path.join(homeDir, 'Downloads'); +export const systemName = os.type(); diff --git a/src/main/main.ts b/src/main/main.ts index c12ac53..9b4ab84 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -48,7 +48,7 @@ import { dbUtil } from '../common/db' import { setConfig } from './setConfig' import { NTQQUserApi } from '../ntqqapi/api/user' import { NTQQGroupApi } from '../ntqqapi/api/group' -import { crychic } from '../ntqqapi/external/crychic' +import { crychic } from '../ntqqapi/native/crychic' import { OB11FriendPokeEvent, OB11GroupPokeEvent } from '../onebot11/event/notice/OB11PokeEvent' import { checkNewVersion, upgradeLLOneBot } from '../common/utils/upgrade' import { log } from '../common/utils/log' diff --git a/src/ntqqapi/api/file.ts b/src/ntqqapi/api/file.ts index b376d51..6ddc106 100644 --- a/src/ntqqapi/api/file.ts +++ b/src/ntqqapi/api/file.ts @@ -12,10 +12,10 @@ import { import path from 'path' import fs from 'fs' import { ReceiveCmdS } from '../hook' -import { log } from '../../common/utils' +import { log } from '@/common/utils' import https from 'https' -import { sleep } from '../../common/utils' -import { hookApi } from '../external/moehook/hook' +import { sleep } from '@/common/utils' +import { hookApi } from '../native/moehook/hook' let privateImageRKey = '' let groupImageRKey = '' diff --git a/src/ntqqapi/external/cpmodule.ts b/src/ntqqapi/external/cpmodule.ts deleted file mode 100644 index ab98263..0000000 --- a/src/ntqqapi/external/cpmodule.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as os from "os"; -import path from "node:path"; -import fs from "fs"; - -export function getModuleWithArchName(moduleName: string) { - const systemPlatform = os.platform() - const cpuArch = os.arch() - return `${moduleName}-${systemPlatform}-${cpuArch}.node` -} - -export function cpModule(moduleName: string) { - const currentDir = path.resolve(__dirname); - const fileName = `./${getModuleWithArchName(moduleName)}` - try { - fs.copyFileSync(path.join(currentDir, fileName), path.join(currentDir, `${moduleName}.node`)); - } catch (e) { - - } -} \ No newline at end of file diff --git a/src/ntqqapi/external/crychic/crychic-win32-x64.node b/src/ntqqapi/external/crychic/crychic-win32-x64.node deleted file mode 100644 index 2f3e843..0000000 Binary files a/src/ntqqapi/external/crychic/crychic-win32-x64.node and /dev/null differ diff --git a/src/ntqqapi/external/crychic/index.ts b/src/ntqqapi/external/crychic/index.ts deleted file mode 100644 index 6de1418..0000000 --- a/src/ntqqapi/external/crychic/index.ts +++ /dev/null @@ -1,54 +0,0 @@ -import {log} from "../../../common/utils"; -import {NTQQApi} from "../../ntcall"; -import {cpModule} from "../cpmodule"; - -type PokeHandler = (id: string, isGroup: boolean) => void -type CrychicHandler = (event: string, id: string, isGroup: boolean) => void - -let pokeRecords: Record = {} - -class Crychic{ - private crychic: any = undefined - - loadNode(){ - if (!this.crychic){ - try { - cpModule('crychic'); - this.crychic = require("./crychic.node") - this.crychic.init() - }catch (e) { - log("crychic加载失败", e) - } - } - } - registerPokeHandler(fn: PokeHandler){ - this.registerHandler((event, id, isGroup)=>{ - if (event === "poke"){ - let existTime = pokeRecords[id] - if (existTime) { - if (Date.now() - existTime < 1500) { - return - } - } - pokeRecords[id] = Date.now() - fn(id, isGroup); - } - }) - } - registerHandler(fn: CrychicHandler){ - if (!this.crychic) return; - this.crychic.setCryHandler(fn) - } - sendFriendPoke(friendUid: string){ - if (!this.crychic) return; - this.crychic.sendFriendPoke(parseInt(friendUid)) - NTQQApi.fetchUnitedCommendConfig().then() - } - sendGroupPoke(groupCode: string, memberUin: string){ - if (!this.crychic) return; - this.crychic.sendGroupPoke(parseInt(memberUin), parseInt(groupCode)) - NTQQApi.fetchUnitedCommendConfig().then() - } -} - -export const crychic = new Crychic() \ No newline at end of file diff --git a/src/ntqqapi/external/moehook/MoeHoo-linux-x64.node b/src/ntqqapi/external/moehook/MoeHoo-linux-x64.node deleted file mode 100644 index 36c4c52..0000000 Binary files a/src/ntqqapi/external/moehook/MoeHoo-linux-x64.node and /dev/null differ diff --git a/src/ntqqapi/external/moehook/MoeHoo-win32-x64.node b/src/ntqqapi/external/moehook/MoeHoo-win32-x64.node deleted file mode 100644 index 85aaac5..0000000 Binary files a/src/ntqqapi/external/moehook/MoeHoo-win32-x64.node and /dev/null differ diff --git a/src/ntqqapi/external/moehook/hook.ts b/src/ntqqapi/external/moehook/hook.ts deleted file mode 100644 index a1dd5fb..0000000 --- a/src/ntqqapi/external/moehook/hook.ts +++ /dev/null @@ -1,34 +0,0 @@ -import * as os from "os"; -import fs from "fs"; -import path from "node:path"; -import {cpModule} from "../cpmodule"; - -interface MoeHook { - GetRkey: () => string, // Return '&rkey=xxx' - HookRkey: () => string -} - - -class HookApi { - private readonly moeHook: MoeHook | null = null; - - constructor() { - cpModule('MoeHoo'); - try { - this.moeHook = require('./MoeHoo.node'); - console.log("hook rkey地址", this.moeHook!.HookRkey()); - } catch (e) { - console.log('加载 moehoo 失败', e); - } - } - - getRKey(): string { - return this.moeHook?.GetRkey() || ''; - } - - isAvailable() { - return !!this.moeHook; - } -} - -export const hookApi = new HookApi(); diff --git a/src/onebot11/action/msg/SendMsg.ts b/src/onebot11/action/msg/SendMsg.ts index b0c25a2..ac8ed36 100644 --- a/src/onebot11/action/msg/SendMsg.ts +++ b/src/onebot11/action/msg/SendMsg.ts @@ -32,7 +32,7 @@ import { ALLOW_SEND_TEMP_MSG, getConfigUtil } from '../../../common/config' import { log } from '../../../common/utils/log' import { sleep } from '../../../common/utils/helper' import { uri2local } from '../../../common/utils' -import { crychic } from '../../../ntqqapi/external/crychic' +import { crychic } from '../../../ntqqapi/native/crychic' import { NTQQGroupApi } from '../../../ntqqapi/api' import { CustomMusicSignPostData, IdMusicSignPostData, MusicSign, MusicSignPostData } from '../../../common/utils/sign' diff --git a/tsconfig.json b/tsconfig.json index c149942..ec46305 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,9 +7,27 @@ "esModuleInterop": true, "allowJs": true, "allowSyntheticDefaultImports": true, - "moduleResolution": "node" + "moduleResolution": "node", // "sourceMap": true + "paths": { + "@/common/*": [ + "./src/common/*" + ], + "@/onebot11/*": [ + "./src/onebot11" + ], + "@/ntqqapi/*": [ + "./src/ntqqapi/*" + ] + } }, - "include": ["src/*", "src/**/*", "scripts/*"], - "exclude": ["node_modules"] + "include": [ + "src/*", + "src/**/*", + "scripts/*" + ], + "exclude": [ + "node_modules" + ], + }