Reorder and tidy imports, re-export types, and apply minor formatting fixes across the bridge package. Changes include: - Reordered imports and grouped related imports in hook-manager, hook-session, pipe-watcher, qq-hook-client, qq-port-probe and others. - Moved several type re-exports (HookProcessBaseInfo, QqPortLoginInfo, HookProcessInfo/Status) in hook-manager and consolidated exports in package entry index.ts. - Minor whitespace/style tweaks: constructor spacing, for-loop formatting, empty catch handlers, and small refactors that do not change runtime behavior. These are non-functional housekeeping changes to improve consistency and readability.
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { PacketSender, SendPacketResult } from '@snowluma/common/packet-sender';
|
|
import { QqHookClient, type QqHookSendReply } from './qq-hook-client';
|
|
|
|
export class HookPacketClient implements PacketSender {
|
|
constructor(private readonly client: QqHookClient) { }
|
|
|
|
async sendPacket(serviceCmd: string, body: Buffer, timeoutMs = 15000): Promise<SendPacketResult> {
|
|
if (!this.client.isLoggedIn) {
|
|
return { success: false, gotResponse: false, errorCode: -1, errorMessage: 'qq_hook client is not logged in', responseData: null };
|
|
}
|
|
|
|
try {
|
|
const reply = await this.client.send(serviceCmd, body, {
|
|
wantReply: true,
|
|
replyTimeoutMs: timeoutMs,
|
|
}) as QqHookSendReply;
|
|
return {
|
|
success: reply.error === 0,
|
|
gotResponse: true,
|
|
errorCode: reply.error,
|
|
errorMessage: reply.message || '',
|
|
responseData: reply.body,
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
success: false,
|
|
gotResponse: false,
|
|
errorCode: -1,
|
|
errorMessage: error instanceof Error ? error.message : String(error),
|
|
responseData: null,
|
|
};
|
|
}
|
|
}
|
|
}
|