fix(onebot): treat a successful status change as success

set_online_status applied the new status but still failed the action
because QQ's success reply text was treated as an error.

Closes #405
This commit is contained in:
DrSmoothl committed 2026-08-20 12:14:05 +08:00
1 parent 8fbddf67bf
commit aaaf0994f6
2 files changed
+25 -3

No files matched your search

+3 -2
View File
@@ -76,8 +76,9 @@ export class ProfileApi {
if (!resp) {
throw new Error(result.errorMessage || 'set online status failed (network/timeout)');
}
if (resp.errCode !== undefined && resp.errCode !== 0) {
throw new Error(resp.errMsg || `set online status failed with errCode: ${resp.errCode}`);
const message = resp.errMsg ?? '';
if (message !== '' && message !== 'set status success') {
throw new Error(message);
}
}
}
+22 -1
View File
@@ -87,9 +87,30 @@ describe('apis/profile', () => {
expect(decoded.batteryStatus ?? 0).toBe(0);
});
it('setOnlineStatus accepts QQ\'s success reply even when the reply code is non-zero (#405)', async () => {
const bridge = mockBridge();
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({
errCode: 1,
errMsg: 'set status success',
}));
expect(respBuf.length).toBeGreaterThan(0);
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
} as any);
await expect(new ProfileApi(bridge as any).setOnlineStatus(10, 0, 100)).resolves.toBeUndefined();
});
it('setOnlineStatus accepts a success-only reply body (#405)', async () => {
const bridge = mockBridge();
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errMsg: 'set status success' }));
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
} as any);
await expect(new ProfileApi(bridge as any).setOnlineStatus(10, 0)).resolves.toBeUndefined();
});
it('setDiyOnlineStatus surfaces server errors via the same path as setOnlineStatus', async () => {
const bridge = mockBridge();
// Build a response that decodes to errCode != 0.
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errCode: 1, errMsg: 'denied' }));
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,