feat(onebot): set profile gender and return stranger online status
set_qq_profile accepts sex. get_stranger_info now returns the online status, extended status, and custom status that QQ already provides on the user profile. Closes #397 Closes #398
This commit is contained in:
11 files changed
+81
-13
No files matched your search
@@ -22,6 +22,7 @@ import type {
|
||||
OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { UserProfileInfo } from '../../qq-info';
|
||||
import { applyOnlineStatus } from './fetch-user-profile';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
const REQUESTED_KEYS = [
|
||||
@@ -83,6 +84,7 @@ export namespace FetchUserProfileByUid {
|
||||
info.sex = sexNum === 1 ? 'male' : sexNum === 2 ? 'female' : 'unknown';
|
||||
info.age = numMap.get(20037) ?? 0;
|
||||
info.level = numMap.get(105) ?? 0;
|
||||
applyOnlineStatus(info, bytesMap, numMap);
|
||||
}
|
||||
|
||||
return info;
|
||||
|
||||
@@ -21,12 +21,37 @@ import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
AvatarInfo,
|
||||
OidbCustomStatus,
|
||||
OidbUserInfoRequest,
|
||||
OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { UserProfileInfo } from '../../qq-info';
|
||||
import { unpackStatusWord } from '../extras/get-stranger-status';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export function applyOnlineStatus(
|
||||
info: UserProfileInfo,
|
||||
bytesMap: Map<number, Uint8Array>,
|
||||
numMap: Map<number, number>,
|
||||
): void {
|
||||
const statusRaw = numMap.get(27372);
|
||||
if (statusRaw !== undefined) {
|
||||
const unpacked = unpackStatusWord(statusRaw);
|
||||
info.status = unpacked.status;
|
||||
info.extStatus = unpacked.ext_status;
|
||||
info.batteryStatus = 0;
|
||||
}
|
||||
const customBytes = bytesMap.get(27406);
|
||||
if (customBytes && customBytes.length > 0) {
|
||||
const custom = protobuf_decode<OidbCustomStatus>(customBytes);
|
||||
info.customStatus = {
|
||||
faceId: custom.faceId ?? 0,
|
||||
wording: custom.msg ?? '',
|
||||
};
|
||||
info.customStatusDesc = custom.msg ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
const REQUESTED_KEYS = [
|
||||
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026,
|
||||
105, 27372, 27406, 20037,
|
||||
@@ -90,6 +115,7 @@ export namespace FetchUserProfile {
|
||||
info.sex = sexNum === 1 ? 'male' : sexNum === 2 ? 'female' : 'unknown';
|
||||
info.age = numMap.get(20037) ?? 0;
|
||||
info.level = numMap.get(105) ?? 0;
|
||||
applyOnlineStatus(info, bytesMap, numMap);
|
||||
}
|
||||
|
||||
return info;
|
||||
|
||||
@@ -16,6 +16,15 @@ export interface StrangerStatus {
|
||||
ext_status: number;
|
||||
}
|
||||
|
||||
export function unpackStatusWord(raw: bigint | number): { status: number; ext_status: number } {
|
||||
const extBig = typeof raw === 'bigint' ? raw : BigInt(raw);
|
||||
if (extBig <= 10n) {
|
||||
return { status: Number(extBig) * 10, ext_status: 0 };
|
||||
}
|
||||
const status = Number((extBig & 0xff00n) + ((extBig >> 16n) & 0xffn));
|
||||
return { status: 10, ext_status: status };
|
||||
}
|
||||
|
||||
const STATUS_PROPERTY_KEY = 27372;
|
||||
|
||||
export namespace GetStrangerStatus {
|
||||
@@ -39,12 +48,7 @@ export namespace GetStrangerStatus {
|
||||
?.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) {
|
||||
return { status: Number(extBig) * 10, ext_status: 0 };
|
||||
}
|
||||
const status = Number((extBig & 0xff00n) + ((extBig >> 16n) & 0xffn));
|
||||
return { status: 10, ext_status: status };
|
||||
return unpackStatusWord(raw);
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbStrangerStatusReq>): Uint8Array =>
|
||||
|
||||
@@ -19,6 +19,7 @@ export namespace SetProfile {
|
||||
export interface Params {
|
||||
nickname?: string;
|
||||
personalNote?: string;
|
||||
sex?: number;
|
||||
}
|
||||
|
||||
/** Needs identity to read `uin` for the request body. */
|
||||
@@ -26,9 +27,15 @@ export namespace SetProfile {
|
||||
|
||||
export const serialize = (ctx: Deps, p: Params): OidbSetProfile => {
|
||||
const stringProfiles: { fieldId: number; value: string }[] = [];
|
||||
const intProfiles: { fieldId: number; value: bigint }[] = [];
|
||||
if (p.nickname !== undefined) stringProfiles.push({ fieldId: 20002, value: p.nickname });
|
||||
if (p.personalNote !== undefined) stringProfiles.push({ fieldId: 102, value: p.personalNote });
|
||||
return { uin: BigInt(ctx.identity.uin), stringProfiles };
|
||||
if (p.sex !== undefined) intProfiles.push({ fieldId: 20009, value: BigInt(p.sex) });
|
||||
return {
|
||||
uin: BigInt(ctx.identity.uin),
|
||||
...(stringProfiles.length > 0 ? { stringProfiles } : {}),
|
||||
...(intProfiles.length > 0 ? { intProfiles } : {}),
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (_ctx: Deps, _: Oidb0x112aResp): void => {};
|
||||
@@ -42,7 +49,11 @@ export namespace SetProfile {
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> => {
|
||||
// No-op when there's nothing to write — preserves the facade's
|
||||
// historic short-circuit (avoid a wasted SSO round-trip).
|
||||
if (params.nickname === undefined && params.personalNote === undefined) {
|
||||
if (
|
||||
params.nickname === undefined
|
||||
&& params.personalNote === undefined
|
||||
&& params.sex === undefined
|
||||
) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return invokeOidb(deps, SetProfile, params);
|
||||
|
||||
@@ -12,6 +12,11 @@ export interface UserProfileInfo {
|
||||
* Already requested in `fetchUserProfile` keys[]; LagrangeV2
|
||||
* `FetchStrangerService.cs` confirms `// Level`. */
|
||||
level: number;
|
||||
status?: number;
|
||||
extStatus?: number;
|
||||
batteryStatus?: number;
|
||||
customStatus?: { faceId: number; wording: string } | null;
|
||||
customStatusDesc?: string;
|
||||
}
|
||||
|
||||
export interface FriendInfo {
|
||||
|
||||
Reference in new issue
Block a user