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
}
async getGroupMembers(groupCode: string, num = 3000): Promise<Map<string, GroupMember>> {
const sceneId = await invoke(NTMethod.GROUP_MEMBER_SCENE, [{ groupCode, scene: 'groupMemberList_MainWindow' }])
async getGroupMembers(groupCode: string, num = 3000) {
const sceneId = await invoke(NTMethod.GROUP_MEMBER_SCENE, [{
groupCode,
scene: 'groupMemberList_MainWindow'
}])
const data = await invoke(NTMethod.GROUP_MEMBERS, [{ sceneId, num }])
if (data.errCode !== 0) {
throw new Error('获取群成员列表出错,' + data.errMsg)

View File

@ -118,7 +118,7 @@ export class NTQQUserApi extends Service {
await this.ctx.sleep(30)
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) {
const unveifyUid = (await this.getUserDetailInfoByUin(uin)).info.uid

View File

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

View File

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

View File

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