feat(onebot): expose qidian account flags on stranger info

Return qidian master and crew flags from get_stranger_info so callers can tell a qidian account from a normal one. Ordinary accounts keep the flags at zero. Existing stranger fields are unchanged.

Refs #404
This commit is contained in:
makotowu authored and GitHub committed 2026-08-22 12:36:22 +08:00
1 parent 6782fd9cb3
commit 83f643f01b
9 files changed
+97 -3

No files matched your search

@@ -47,6 +47,9 @@ function emptyProfile(uin: number, uid: string) {
sign: '',
avatar: '',
level: 0,
qidianMasterFlag: 0,
qidianCrewFlag: 0,
qidianCrewFlag2: 0,
};
}
+11 -2
View File
@@ -757,6 +757,9 @@ describe('IdentityService', () => {
sign: '',
avatar: '',
level: 0,
qidianMasterFlag: 0,
qidianCrewFlag: 0,
qidianCrewFlag2: 0,
};
const request = {
groupId: GROUP_ID,
@@ -911,7 +914,10 @@ describe('IdentityService', () => {
describe('IdentityService.resolveUid', () => {
function makeProfile(uin: number, uid: string): UserProfileInfo {
return { uin, uid, nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0 };
return {
uin, uid, nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
};
}
it('returns the cached uid without invoking the fetcher', async () => {
@@ -976,7 +982,10 @@ describe('IdentityService.resolveUid', () => {
describe('IdentityService inbound UID→UIN', () => {
function makeProfile(uin: number, uid: string): UserProfileInfo {
return { uin, uid, nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0 };
return {
uin, uid, nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
};
}
it('findUinByUid treats a numeric uid as that uin without consulting maps', () => {
+1
View File
@@ -525,6 +525,7 @@ async function warmUpBridgeState(
uin: f.uin, uid: f.uid,
nickname: f.nickname || uin,
remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
});
bridge.identity.nickname = f.nickname || uin;
log.debug('self info: UIN=%s uid=%s nickname=%s', uin, f.uid, f.nickname ?? '');
@@ -296,6 +296,9 @@ function formatStrangerInfo(p: UserProfileInfo): JsonObject {
batteryStatus: p.batteryStatus ?? 0,
customStatus: p.customStatus ?? null,
customStatusDescInfo: p.customStatusDesc ?? '',
qidian_master_flag: p.qidianMasterFlag,
qidian_crew_flag: p.qidianCrewFlag,
qidian_crew_flag_2: p.qidianCrewFlag2,
};
}
+20 -1
View File
@@ -104,7 +104,8 @@ function makeProfile(
remark = '',
): UserProfileInfo {
return {
uin, uid: `u_${uin}`, nickname, remark, qid: '', sex, age, sign, avatar: '',
uin, uid: `u_${uin}`, nickname, remark, qid: '', sex, age, sign, avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
};
}
@@ -547,6 +548,24 @@ describe('onebot/contact-actions / getStrangerInfo', () => {
});
});
it('passes through the qidian (企点) flags from the profile', async () => {
const bridge = fakeBridge({
fetchUserProfile: vi.fn(async () => ({
...makeProfile(55555, 'QidianWorker', 'male'),
qidianMasterFlag: 0,
qidianCrewFlag: 1,
qidianCrewFlag2: 0,
})),
});
const out = await getStrangerInfo(bridge, 55555);
expect(out).toMatchObject({
user_id: 55555,
qidian_master_flag: 0,
qidian_crew_flag: 1,
qidian_crew_flag_2: 0,
});
});
it('falls back to identity.findUserProfile when fetch fails but the profile is cached', async () => {
const bridge = fakeBridge({
fetchUserProfile: vi.fn(async () => { throw new Error('net'); }),
@@ -28,6 +28,8 @@ import { invokeOidb, type OidbSender } from '../../oidb-service';
const REQUESTED_KEYS = [
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026,
105, 27372, 27406, 20037,
// 企点标志(QQ 企点 / 企业版 QQ 账号):员工号实测为 1,普通账号为 0
40410, 42031,
];
export namespace FetchUserProfileByUid {
@@ -55,6 +57,7 @@ export namespace FetchUserProfileByUid {
uin: body.body.uin ?? 0,
uid: body.body.uid ?? '',
nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
};
if (body.body.properties) {
@@ -85,6 +88,9 @@ export namespace FetchUserProfileByUid {
info.age = numMap.get(20037) ?? 0;
info.level = numMap.get(105) ?? 0;
applyOnlineStatus(info, bytesMap, numMap);
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
info.qidianMasterFlag = numMap.get(42031) ?? 0;
info.qidianCrewFlag = numMap.get(40410) ?? 0;
}
return info;
@@ -55,6 +55,8 @@ export function applyOnlineStatus(
const REQUESTED_KEYS = [
20002, 27394, 20009, 20031, 101, 103, 102, 20020, 20003, 20026,
105, 27372, 27406, 20037,
// 企点标志(QQ 企点 / 企业版 QQ 账号):员工号实测为 1,普通账号为 0
40410, 42031,
];
export namespace FetchUserProfile {
@@ -86,6 +88,7 @@ export namespace FetchUserProfile {
uin: body.body.uin ?? requestedUin,
uid: body.body.uid ?? '',
nickname: '', remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '', level: 0,
qidianMasterFlag: 0, qidianCrewFlag: 0, qidianCrewFlag2: 0,
};
if (body.body.properties) {
@@ -116,6 +119,9 @@ export namespace FetchUserProfile {
info.age = numMap.get(20037) ?? 0;
info.level = numMap.get(105) ?? 0;
applyOnlineStatus(info, bytesMap, numMap);
// 企点标志:40410 / 42031,服务器仅在返回时才出现(普通账号缺省 → 0)
info.qidianMasterFlag = numMap.get(42031) ?? 0;
info.qidianCrewFlag = numMap.get(40410) ?? 0;
}
return info;
+10
View File
@@ -17,6 +17,16 @@ export interface UserProfileInfo {
batteryStatus?: number;
customStatus?: { faceId: number; wording: string } | null;
customStatusDesc?: string;
/**
* 企点标志(QQ 企点 / 企业版 QQ 账号),0/1。
* 数据来源为 OIDB 0xFE1_2 number-property key 40410 / 42031:
* 真实企点员工号上实测均为 1,普通账号均为 0(见 issue #404 讨论)。
* 与 NapCat `simpleInfo.relationFlags` 的 qidianMasterFlag / qidianCrewFlag
* 对应;qidianCrewFlag2 未发现独立 key,恒为 0。
*/
qidianMasterFlag: number;
qidianCrewFlag: number;
qidianCrewFlag2: number;
}
export interface FriendInfo {
@@ -44,6 +44,43 @@ describe('FetchUserProfile namespace', () => {
expect(keys).toContain(101); // avatar
expect(keys).toContain(102); // sign
expect(keys).toContain(103); // remark
expect(keys).toContain(40410); // qidian crew flag (企点员工标志)
expect(keys).toContain(42031); // qidian master flag (企点主号标志)
});
it('decodes qidian flags from number-properties (0 when absent)', async () => {
// 企点员工号:两个标志均为 1;普通账号服务器不返回这两个 key → 缺省 0
const qidian = makeSender({
body: {
uin: 3004251964, uid: 'u',
properties: {
bytesProperties: [],
numberProperties: [
{ number1: 40410, number2: 1 },
{ number1: 42031, number2: 1 },
],
},
} as any,
});
const out = await FetchUserProfile.invoke(qidian, { uin: 3004251964 });
expect(out.qidianMasterFlag).toBe(1);
expect(out.qidianCrewFlag).toBe(1);
expect(out.qidianCrewFlag2).toBe(0);
// 普通账号:无企点 key → 全 0
const normal = makeSender({
body: {
uin: 10001, uid: 'u',
properties: {
bytesProperties: [],
numberProperties: [{ number1: 20009, number2: 1 }],
},
} as any,
});
const out2 = await FetchUserProfile.invoke(normal, { uin: 10001 });
expect(out2.qidianMasterFlag).toBe(0);
expect(out2.qidianCrewFlag).toBe(0);
expect(out2.qidianCrewFlag2).toBe(0);
});
it('decodes nickname / remark / qid / sign from bytes-properties', async () => {