diff --git a/packages/core/src/bridge/apis/profile.ts b/packages/core/src/bridge/apis/profile.ts index d848afb8..4deec9b2 100644 --- a/packages/core/src/bridge/apis/profile.ts +++ b/packages/core/src/bridge/apis/profile.ts @@ -82,8 +82,8 @@ export class ProfileApi { } } - setProfile(nickname?: string, personalNote?: string): Promise { - return SetProfile.invoke(this.ctx, { nickname, personalNote }); + setProfile(nickname?: string, personalNote?: string, sex?: number): Promise { + return SetProfile.invoke(this.ctx, { nickname, personalNote, sex }); } setSelfLongNick(longNick: string): Promise { diff --git a/packages/onebot/src/actions/friend.ts b/packages/onebot/src/actions/friend.ts index cbf9006b..92e4a7b7 100644 --- a/packages/onebot/src/actions/friend.ts +++ b/packages/onebot/src/actions/friend.ts @@ -44,6 +44,12 @@ export const actions = [ long_nick: { type: 'string', description: '个性签名' }, qq_level: { type: 'integer', description: 'QQ 等级(仅查到资料时返回)' }, level: { type: 'integer', description: 'QQ 等级,同 qq_level(仅查到资料时返回)' }, + status: { type: 'integer', description: '在线状态码' }, + extStatus: { type: 'integer', description: '扩展状态码' }, + ext_status: { type: 'integer', description: '扩展状态码(同 extStatus)' }, + batteryStatus: { type: 'integer', description: '电量状态' }, + customStatus: { type: 'object', description: '自定义状态', nullable: true }, + customStatusDescInfo: { type: 'string', description: '自定义状态说明' }, }, required: ['user_id', 'nickname', 'remark', 'sex', 'age', 'long_nick'], }, diff --git a/packages/proto-defs/src/oidb-actions/base.ts b/packages/proto-defs/src/oidb-actions/base.ts index 66b79a81..33940b1c 100644 --- a/packages/proto-defs/src/oidb-actions/base.ts +++ b/packages/proto-defs/src/oidb-actions/base.ts @@ -86,9 +86,9 @@ export interface Oidb0x89a_0HistoryVisibility { settings?: pb<2, Oidb0x89a_0HistoryVisibilitySettings>; field12?: pb<12, uint_32>; } -// 0x89A_8 — one masked group-member capability update. These are deny bits, +// 0x89A_0 — one masked group-member capability update. These are deny bits, // so callers clear the selected bit to allow a capability and set it to deny. -// Same settings tags as invite policy; the command variant is what differs. +// Same settings tags as invite policy. export interface Oidb0x89a_0MemberPermissionSettings { appPrivilegeFlag?: pb_optional<23, uint_32>; appPrivilegeMask?: pb_optional<24, uint_32>; @@ -266,6 +266,10 @@ export interface OidbUserInfoResponse { export interface AvatarInfo { url?: pb<5, string>; } +export interface OidbCustomStatus { + faceId?: pb<1, uint_32>; + msg?: pb<2, string>; +} export interface OidbFriendListNumber { numbers?: pb_repeated<1, uint_32>; } diff --git a/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts b/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts index 2d046e9e..764b3151 100644 --- a/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts +++ b/packages/protocol/src/oidb-services/contacts/fetch-user-profile-by-uid.ts @@ -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; diff --git a/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts b/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts index ad682b3d..078c7704 100644 --- a/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts +++ b/packages/protocol/src/oidb-services/contacts/fetch-user-profile.ts @@ -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, + numMap: Map, +): 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(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; diff --git a/packages/protocol/src/oidb-services/extras/get-stranger-status.ts b/packages/protocol/src/oidb-services/extras/get-stranger-status.ts index e07420c5..12472f17 100644 --- a/packages/protocol/src/oidb-services/extras/get-stranger-status.ts +++ b/packages/protocol/src/oidb-services/extras/get-stranger-status.ts @@ -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): Uint8Array => diff --git a/packages/protocol/src/oidb-services/profile/set-profile.ts b/packages/protocol/src/oidb-services/profile/set-profile.ts index 972fcdba..e171fe2f 100644 --- a/packages/protocol/src/oidb-services/profile/set-profile.ts +++ b/packages/protocol/src/oidb-services/profile/set-profile.ts @@ -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 => { // 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); diff --git a/packages/protocol/src/qq-info.ts b/packages/protocol/src/qq-info.ts index ca38a517..c1203eb9 100644 --- a/packages/protocol/src/qq-info.ts +++ b/packages/protocol/src/qq-info.ts @@ -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 { diff --git a/packages/protocol/tests/oidb-services/profile/set-profile.test.ts b/packages/protocol/tests/oidb-services/profile/set-profile.test.ts index 348f56c1..65b92dd0 100644 --- a/packages/protocol/tests/oidb-services/profile/set-profile.test.ts +++ b/packages/protocol/tests/oidb-services/profile/set-profile.test.ts @@ -21,6 +21,14 @@ describe('SetProfile namespace', () => { }); describe('invoke', () => { + it('packages sex into integer field 20009', async () => { + const deps = makeDeps(); + await SetProfile.invoke(deps, { sex: 1 }); + const [, bytes] = deps.sendRawPacket.mock.calls[0]!; + const env = protobuf_decode>(bytes); + expect(env.body?.intProfiles).toEqual([{ fieldId: 20009, value: 1n }]); + }); + it('is a no-op when both nickname and personalNote are undefined', async () => { const deps = makeDeps(); await SetProfile.invoke(deps, {}); diff --git a/packages/sdk/src/client/api-client.ts b/packages/sdk/src/client/api-client.ts index 7ad2d3c4..3ef1c548 100644 --- a/packages/sdk/src/client/api-client.ts +++ b/packages/sdk/src/client/api-client.ts @@ -455,10 +455,11 @@ export abstract class SnowLumaApiClient { return this.call('download_file', params, options); } - setQqProfile(params: { nickname?: string; personalNote?: string }, options?: RequestOptions) { + setQqProfile(params: { nickname?: string; personalNote?: string; sex?: number }, options?: RequestOptions) { return this.call('set_qq_profile', { nickname: params.nickname, personal_note: params.personalNote, + ...(params.sex !== undefined ? { sex: params.sex } : {}), }, options); } diff --git a/packages/sdk/src/types/params.ts b/packages/sdk/src/types/params.ts index c52b2bc9..20e745e0 100644 --- a/packages/sdk/src/types/params.ts +++ b/packages/sdk/src/types/params.ts @@ -350,6 +350,7 @@ export interface DownloadFileParams extends JsonObject { export interface SetQqProfileParams extends JsonObject { nickname?: string; personal_note?: string; + sex?: number; } export interface SetOnlineStatusParams extends JsonObject {