This commit is contained in:
idranme 2024-10-13 16:31:04 +08:00
parent c8e897abdb
commit d3abaf806f
5 changed files with 20 additions and 10 deletions

View File

@ -45,8 +45,11 @@ export class NTQQGroupApi extends Service {
return result.groupList return result.groupList
} }
async getGroupMembers(groupCode: string, num = 3000): Promise<Map<string, GroupMember>> { async getGroupMembers(groupCode: string, num = 3000) {
const sceneId = await invoke(NTMethod.GROUP_MEMBER_SCENE, [{ groupCode, scene: 'groupMemberList_MainWindow' }]) const sceneId = await invoke(NTMethod.GROUP_MEMBER_SCENE, [{
groupCode,
scene: 'groupMemberList_MainWindow'
}])
const data = await invoke(NTMethod.GROUP_MEMBERS, [{ sceneId, num }]) const data = await invoke(NTMethod.GROUP_MEMBERS, [{ sceneId, num }])
if (data.errCode !== 0) { if (data.errCode !== 0) {
throw new Error('获取群成员列表出错,' + data.errMsg) throw new Error('获取群成员列表出错,' + data.errMsg)

View File

@ -118,7 +118,7 @@ export class NTQQUserApi extends Service {
await this.ctx.sleep(30) await this.ctx.sleep(30)
member = await this.ctx.ntGroupApi.searchMember(groupCode, uin) member = await this.ctx.ntGroupApi.searchMember(groupCode, uin)
} }
uid = member.values().find(e => e.uin === uin)?.uid uid = Array.from(member.values()).find(e => e.uin === uin)?.uid
} }
if (!uid) { if (!uid) {
const unveifyUid = (await this.getUserDetailInfoByUin(uin)).info.uid const unveifyUid = (await this.getUserDetailInfoByUin(uin)).info.uid

View File

@ -1,7 +1,6 @@
import { Context } from 'cordis' import { Context } from 'cordis'
import { Dict } from 'cosmokit' import { Dict } from 'cosmokit'
import { getBuildVersion } from '@/common/utils/misc' import { getBuildVersion } from '@/common/utils/misc'
// @ts-expect-error: Unreachable code error
import addon from './external/crychic-win32-x64.node?asset' import addon from './external/crychic-win32-x64.node?asset'
export class Native { export class Native {
@ -35,7 +34,7 @@ export class Native {
} }
try { try {
this.crychic = require(addon) this.crychic = require(addon)
this.crychic.init() this.crychic!.init()
} catch (e) { } catch (e) {
this.ctx.logger.warn('crychic 加载失败', e) this.ctx.logger.warn('crychic 加载失败', e)
} }

View File

@ -124,7 +124,12 @@ export function invoke<
return new Promise<R>((resolve, reject) => { return new Promise<R>((resolve, reject) => {
const apiArgs = [method, ...args] const apiArgs = [method, ...args]
const callbackId = randomUUID() const callbackId = randomUUID()
let eventId: string
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
if (eventId) {
removeReceiveHook(eventId)
}
log(`ntqq api timeout ${channel}, ${eventName}, ${method}`, args) log(`ntqq api timeout ${channel}, ${eventName}, ${method}`, args)
reject(`ntqq api timeout ${channel}, ${eventName}, ${method}, ${JSON.stringify(args)}`) reject(`ntqq api timeout ${channel}, ${eventName}, ${method}, ${JSON.stringify(args)}`)
}, timeout) }, timeout)
@ -140,16 +145,16 @@ export function invoke<
let result: unknown let result: unknown
// 这里的callback比较特殊QQ后端先返回是否调用成功再返回一条结果数据 // 这里的callback比较特殊QQ后端先返回是否调用成功再返回一条结果数据
const secondCallback = () => { const secondCallback = () => {
const hookId = registerReceiveHook<R>(options.cbCmd!, (payload) => { eventId = registerReceiveHook<R>(options.cbCmd!, (payload) => {
if (options.cmdCB) { if (options.cmdCB) {
if (options.cmdCB(payload, result)) { if (options.cmdCB(payload, result)) {
removeReceiveHook(hookId) removeReceiveHook(eventId)
clearTimeout(timeoutId) clearTimeout(timeoutId)
resolve(payload) resolve(payload)
} }
} }
else { else {
removeReceiveHook(hookId) removeReceiveHook(eventId)
clearTimeout(timeoutId) clearTimeout(timeoutId)
resolve(payload) resolve(payload)
} }

View File

@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ESNext", "target": "ES2023",
"module": "CommonJS", "module": "CommonJS",
"outDir": "./dist", "outDir": "./dist",
"strict": true, "strict": true,
@ -20,7 +20,10 @@
"./src/ntqqapi/*" "./src/ntqqapi/*"
] ]
}, },
"noEmit": true "noEmit": true,
"types": [
"electron-vite/node"
]
}, },
"include": [ "include": [
"src", "src",