refactor: path alias

fix: moehook
This commit is contained in:
linyuchen 2024-05-10 20:23:30 +08:00
parent 78bb36a2bb
commit 25c7a6096d
15 changed files with 116 additions and 131 deletions

View File

@ -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/' },
],
}),
],

View File

@ -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<any>;
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'

View File

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

View File

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

View File

@ -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();

View File

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

View File

@ -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 = ''

View File

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

View File

@ -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<string, number> = {}
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()

View File

@ -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();

View File

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

View File

@ -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"
],
}