fix(onebot): decode user status property list (#330)
This commit is contained in:
5 files changed
+86
-28
No files matched your search
@@ -1,17 +1,11 @@
|
||||
// 0xFE1_2 — fetch the stranger's status (online / away / busy /
|
||||
// invisible). Same OIDB cmd as fetchUserProfile but a different
|
||||
// request shape (only key 27372 = status, no other property keys),
|
||||
// and we decode the ext-bigint status word into napcat's
|
||||
// (status × 10, ext_status) pair.
|
||||
// 0xFE1_2 — fetch a user's online / extended status. The request asks
|
||||
// for property 27372; the response returns a property-list wrapper,
|
||||
// whose entries must be matched by key rather than by position.
|
||||
//
|
||||
// `uinForm` is set so the server takes the UIN-form validation path;
|
||||
// without it newer NTQQ rejects with `[oidb] one of uid/openid is
|
||||
// invaild`. Same flag fetchUserProfile uses.
|
||||
//
|
||||
// On any transport / decode failure the deserialize step is bypassed
|
||||
// — the facade swallows the namespace-level exception and surfaces
|
||||
// `null` so callers get a clean retcode.
|
||||
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbStrangerStatusReq, OidbStrangerStatusResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
@@ -22,6 +16,8 @@ export interface StrangerStatus {
|
||||
ext_status: number;
|
||||
}
|
||||
|
||||
const STATUS_PROPERTY_KEY = 27372;
|
||||
|
||||
export namespace GetStrangerStatus {
|
||||
export const command = 0xFE1;
|
||||
export const subCommand = 2;
|
||||
@@ -35,11 +31,13 @@ export namespace GetStrangerStatus {
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbStrangerStatusReq => ({
|
||||
uin: p.uin,
|
||||
key: [{ key: 27372 }],
|
||||
key: [{ key: STATUS_PROPERTY_KEY }],
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbStrangerStatusResp): StrangerStatus | null => {
|
||||
const raw = body.data?.status?.value;
|
||||
const raw = body.data?.properties?.entries
|
||||
?.find((entry) => entry.key === STATUS_PROPERTY_KEY)
|
||||
?.value;
|
||||
if (raw === undefined || raw === null) return null;
|
||||
const extBig = typeof raw === 'bigint' ? raw : BigInt(raw);
|
||||
if (extBig <= 10n) {
|
||||
|
||||
Reference in new issue
Block a user