diff --git a/main/src/client/NapCatClient/client.ts b/main/src/client/NapCatClient/client.ts index 2f34291..1390b16 100644 --- a/main/src/client/NapCatClient/client.ts +++ b/main/src/client/NapCatClient/client.ts @@ -40,12 +40,12 @@ export class NapCatClient extends QQClient { }); } - private readonly echoMap: { [key: string]: { resolve: (result: any) => void; reject: (result: any) => void } } = {}; + private readonly echoMap = new Map void; reject: (result: any) => void }>(); public async callApi(action: T, params?: WSSendParam[T]): Promise { return new Promise((resolve, reject) => { const echo = `${new Date().getTime()}${random.int(100000, 999999)}`; - this.echoMap[echo] = { resolve, reject }; + this.echoMap.set(echo, { resolve, reject }); this.ws.send(JSON.stringify({ action, params, echo })); this.logger.debug('send', JSON.stringify({ action, params, echo })); }); @@ -55,8 +55,9 @@ export class NapCatClient extends QQClient { this.logger.debug('receive', message); const data = JSON.parse(message) as WSReceiveHandler[keyof WSReceiveHandler] & { echo: string; status: 'ok' | 'error'; data: any; message: string }; if (data.echo) { - const promise = this.echoMap[data.echo]; + const promise = this.echoMap.get(data.echo); if (!promise) return; + this.echoMap.delete(data.echo); if (data.status === 'ok') { promise.resolve(data.data); } diff --git a/main/src/client/NapCatClient/convert.ts b/main/src/client/NapCatClient/convert.ts index 3104961..41b7386 100644 --- a/main/src/client/NapCatClient/convert.ts +++ b/main/src/client/NapCatClient/convert.ts @@ -62,7 +62,7 @@ export const messageElemToNapCatSendable = async (elem: SendableElem): Promise<{ type: elem.type, data: { file: elem.file, - summary: elem.type, + summary: 'Q2TG ' + elem.type, name: elem.type, }, } as any,