diff --git a/src/ntqqapi/native/cpmodule.ts b/src/ntqqapi/native/cpmodule.ts new file mode 100644 index 0000000..ab98263 --- /dev/null +++ b/src/ntqqapi/native/cpmodule.ts @@ -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) { + + } +} \ No newline at end of file diff --git a/src/ntqqapi/native/crychic/crychic-win32-x64.node b/src/ntqqapi/native/crychic/crychic-win32-x64.node new file mode 100644 index 0000000..2f3e843 Binary files /dev/null and b/src/ntqqapi/native/crychic/crychic-win32-x64.node differ diff --git a/src/ntqqapi/native/crychic/index.ts b/src/ntqqapi/native/crychic/index.ts new file mode 100644 index 0000000..6de1418 --- /dev/null +++ b/src/ntqqapi/native/crychic/index.ts @@ -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 = {} + +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/native/moehook/hook.ts b/src/ntqqapi/native/moehook/hook.ts new file mode 100644 index 0000000..c52c2d2 --- /dev/null +++ b/src/ntqqapi/native/moehook/hook.ts @@ -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();