feat(onebot): expose extended account profile information
Add account identifiers, compatible level names, available registration and membership details, and documented account age for group members. Keep unavailable values absent and refresh the action documentation. Fixes #496
This commit is contained in:
11 files changed
+243
-8
No files matched your search
@@ -22,12 +22,13 @@ import type {
|
||||
OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { UserProfileInfo } from '../../qq-info';
|
||||
import { applyOnlineStatus } from './fetch-user-profile';
|
||||
import { applyOnlineStatus, applyProfileDetails } from './fetch-user-profile';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
const REQUESTED_KEYS = [
|
||||
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026,
|
||||
105, 27372, 27406, 20037,
|
||||
41756, 41757, 42241,
|
||||
// 企点标志(QQ 企点 / 企业版 QQ 账号):员工号实测为 1,普通账号为 0
|
||||
40410, 42031,
|
||||
];
|
||||
@@ -88,6 +89,7 @@ export namespace FetchUserProfileByUid {
|
||||
info.age = numMap.get(20037) ?? 0;
|
||||
info.level = numMap.get(105) ?? 0;
|
||||
applyOnlineStatus(info, bytesMap, numMap);
|
||||
applyProfileDetails(info, numMap);
|
||||
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
|
||||
info.qidianMasterFlag = numMap.get(42031) ?? 0;
|
||||
info.qidianCrewFlag = numMap.get(40410) ?? 0;
|
||||
|
||||
@@ -52,9 +52,29 @@ export function applyOnlineStatus(
|
||||
}
|
||||
}
|
||||
|
||||
export function applyProfileDetails(info: UserProfileInfo, numMap: Map<number, number>): void {
|
||||
const registered = numMap.get(20026);
|
||||
if (registered !== undefined && registered > 0) info.regTime = registered;
|
||||
const flags = numMap.get(41756);
|
||||
if (flags !== undefined) {
|
||||
info.vipFlag = (flags & 1) !== 0;
|
||||
info.yearVipFlag = (flags & 2) !== 0;
|
||||
info.svipFlag = (flags & 0x100) !== 0;
|
||||
}
|
||||
const level = numMap.get(41757);
|
||||
if (level !== undefined) {
|
||||
const mask = level & 0xFFF;
|
||||
if (mask !== 0) info.vipLevel = 33 - Math.clz32(mask);
|
||||
else if (info.vipFlag || info.yearVipFlag || info.svipFlag || numMap.get(42241) === 1) {
|
||||
info.vipLevel = 1;
|
||||
} else if (flags !== undefined && numMap.has(42241)) info.vipLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const REQUESTED_KEYS = [
|
||||
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026,
|
||||
105, 27372, 27406, 20037,
|
||||
41756, 41757, 42241,
|
||||
// 企点标志(QQ 企点 / 企业版 QQ 账号):员工号实测为 1,普通账号为 0
|
||||
40410, 42031,
|
||||
];
|
||||
@@ -119,6 +139,7 @@ export namespace FetchUserProfile {
|
||||
info.age = numMap.get(20037) ?? 0;
|
||||
info.level = numMap.get(105) ?? 0;
|
||||
applyOnlineStatus(info, bytesMap, numMap);
|
||||
applyProfileDetails(info, numMap);
|
||||
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
|
||||
info.qidianMasterFlag = numMap.get(42031) ?? 0;
|
||||
info.qidianCrewFlag = numMap.get(40410) ?? 0;
|
||||
|
||||
@@ -12,6 +12,11 @@ export interface UserProfileInfo {
|
||||
* Already requested in `fetchUserProfile` keys[]; LagrangeV2
|
||||
* `FetchStrangerService.cs` confirms `// Level`. */
|
||||
level: number;
|
||||
regTime?: number;
|
||||
vipFlag?: boolean;
|
||||
yearVipFlag?: boolean;
|
||||
svipFlag?: boolean;
|
||||
vipLevel?: number;
|
||||
status?: number;
|
||||
extStatus?: number;
|
||||
batteryStatus?: number;
|
||||
|
||||
@@ -2,11 +2,12 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
AvatarInfo, OidbUserInfoRequest, OidbUserInfoResponse,
|
||||
AvatarInfo, OidbUserInfoRequest, OidbUserInfoByUidRequest, OidbUserInfoResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { FetchUserProfile } from '../../../src/oidb-services/contacts/fetch-user-profile';
|
||||
import { FetchUserProfileByUid } from '../../../src/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
|
||||
function makeSender(body?: OidbUserInfoResponse) {
|
||||
const responseData = body !== undefined
|
||||
@@ -24,6 +25,48 @@ describe('FetchUserProfile namespace', () => {
|
||||
});
|
||||
|
||||
describe('invoke (e2e)', () => {
|
||||
it.each(['uin', 'uid'])('preserves registration and membership through the %s request', async form => {
|
||||
const sender = makeSender({ body: { uin: 10001, uid: 'u_test', properties: {
|
||||
numberProperties: [
|
||||
{ number1: 20026, number2: 1_200_000_000 },
|
||||
{ number1: 41756, number2: 0x103 },
|
||||
{ number1: 41757, number2: 1 << 5 },
|
||||
{ number1: 42241, number2: 0 },
|
||||
],
|
||||
} } });
|
||||
const profile = form === 'uin'
|
||||
? await FetchUserProfile.invoke(sender, { uin: 10001 })
|
||||
: await FetchUserProfileByUid.invoke(sender, { uid: 'u_test' });
|
||||
expect(profile).toMatchObject({
|
||||
regTime: 1_200_000_000, vipFlag: true, yearVipFlag: true, svipFlag: true, vipLevel: 7,
|
||||
});
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
const request = form === 'uin'
|
||||
? protobuf_decode<OidbBase<OidbUserInfoRequest>>(bytes)
|
||||
: protobuf_decode<OidbBase<OidbUserInfoByUidRequest>>(bytes);
|
||||
expect(request.body?.keys?.map(k => k.key))
|
||||
.toEqual(expect.arrayContaining([20026, 41756, 41757, 42241]));
|
||||
});
|
||||
|
||||
it.each([
|
||||
[0, 0, 0], [1, 0, 1], [0x100, 1, 2], [0x103, 0x801, 13],
|
||||
])('decodes membership flags %i and level mask %i as level %i', async (flags, mask, level) => {
|
||||
const sender = makeSender({ body: { uin: 10001, properties: { numberProperties: [
|
||||
{ number1: 41756, number2: flags }, { number1: 41757, number2: mask },
|
||||
{ number1: 42241, number2: 0 },
|
||||
] } } });
|
||||
expect(await FetchUserProfile.invoke(sender, { uin: 10001 })).toMatchObject({
|
||||
vipFlag: !!(flags & 1), yearVipFlag: !!(flags & 2), svipFlag: !!(flags & 0x100), vipLevel: level,
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps missing registration and membership fields unavailable', async () => {
|
||||
const profile = await FetchUserProfile.invoke(makeSender({ body: { uin: 10001 } }), { uin: 10001 });
|
||||
for (const name of ['regTime', 'vipFlag', 'yearVipFlag', 'svipFlag', 'vipLevel']) {
|
||||
expect(profile).not.toHaveProperty(name);
|
||||
}
|
||||
});
|
||||
|
||||
it('routes to OidbSvcTrpcTcp.0xfe1_2 with reserved=1', async () => {
|
||||
const sender = makeSender({ body: { uin: 10001, uid: 'u' } as any });
|
||||
await FetchUserProfile.invoke(sender, { uin: 10001 });
|
||||
|
||||
Reference in new issue
Block a user