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
@@ -82,8 +82,8 @@ export class ProfileApi {
|
||||
}
|
||||
}
|
||||
|
||||
setProfile(nickname?: string, personalNote?: string): Promise<void> {
|
||||
return SetProfile.invoke(this.ctx, { nickname, personalNote });
|
||||
setProfile(nickname?: string, personalNote?: string, sex?: number): Promise<void> {
|
||||
return SetProfile.invoke(this.ctx, { nickname, personalNote, sex });
|
||||
}
|
||||
|
||||
setSelfLongNick(longNick: string): Promise<void> {
|
||||
|
||||
@@ -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'],
|
||||
},
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<OidbBase<OidbSetProfile>>(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, {});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user