mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
refactor: Rename native node module dirname
This commit is contained in:
parent
9b3916307a
commit
9692bf6ec6
19
src/ntqqapi/native/cpmodule.ts
Normal file
19
src/ntqqapi/native/cpmodule.ts
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
BIN
src/ntqqapi/native/crychic/crychic-win32-x64.node
Normal file
BIN
src/ntqqapi/native/crychic/crychic-win32-x64.node
Normal file
Binary file not shown.
54
src/ntqqapi/native/crychic/index.ts
Normal file
54
src/ntqqapi/native/crychic/index.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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()
|
33
src/ntqqapi/native/moehook/hook.ts
Normal file
33
src/ntqqapi/native/moehook/hook.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {cpModule} from "../cpmodule";
|
||||||
|
import { qqPkgInfo } from '@/common/utils/QQBasicInfo'
|
||||||
|
|
||||||
|
interface MoeHook {
|
||||||
|
GetRkey: () => string, // Return '&rkey=xxx'
|
||||||
|
HookRkey: (version: string) => string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class HookApi {
|
||||||
|
private readonly moeHook: MoeHook | null = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
cpModule('MoeHoo');
|
||||||
|
try {
|
||||||
|
this.moeHook = require('./MoeHoo.node');
|
||||||
|
console.log("hook rkey qq version", this.moeHook!.HookRkey(qqPkgInfo.version));
|
||||||
|
console.log("hook rkey地址", this.moeHook!.HookRkey(qqPkgInfo.version));
|
||||||
|
} catch (e) {
|
||||||
|
console.log('加载 moehoo 失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getRKey(): string {
|
||||||
|
return this.moeHook?.GetRkey() || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
isAvailable() {
|
||||||
|
return !!this.moeHook;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const hookApi = new HookApi();
|
Loading…
x
Reference in New Issue
Block a user