mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: import native .node
This commit is contained in:
parent
58f544862b
commit
91089cdb9e
19
src/ntqqapi/external/cpmodule.ts
vendored
Normal file
19
src/ntqqapi/external/cpmodule.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
5
src/ntqqapi/external/crychic/index.ts
vendored
5
src/ntqqapi/external/crychic/index.ts
vendored
@ -1,5 +1,6 @@
|
||||
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
|
||||
@ -12,12 +13,12 @@ class Crychic{
|
||||
loadNode(){
|
||||
if (!this.crychic){
|
||||
try {
|
||||
this.crychic = require("./crychic-win32-x64.node")
|
||||
cpModule('crychic');
|
||||
this.crychic = require("./crychic.node")
|
||||
this.crychic.init()
|
||||
}catch (e) {
|
||||
log("crychic加载失败", e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
registerPokeHandler(fn: PokeHandler){
|
||||
|
9
src/ntqqapi/external/moehook/hook.ts
vendored
9
src/ntqqapi/external/moehook/hook.ts
vendored
@ -1,5 +1,7 @@
|
||||
import {log} from "../../../common/utils";
|
||||
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'
|
||||
@ -11,10 +13,9 @@ class HookApi {
|
||||
private readonly moeHook: MoeHook | null = null;
|
||||
|
||||
constructor() {
|
||||
cpModule('MoeHoo');
|
||||
try {
|
||||
const systemPlatform = os.platform();
|
||||
const cpuArch = os.arch();
|
||||
this.moeHook = require(`./MoeHoo-${systemPlatform}-${cpuArch}.node`);
|
||||
this.moeHook = require('./MoeHoo.node');
|
||||
console.log("hook rkey地址", this.moeHook!.HookRkey());
|
||||
} catch (e) {
|
||||
console.log('加载 moehoo 失败', e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user