feat(onebot): TierB ③ — RE'd OIDB actions (ark share / doubt friends / robot-add)
All recovered from QQNT wrapper.linux.node via IDA — NapCat ships these as
kernel-only with no portable packet wire, so each cmd + protobuf was traced
from the binary (worker ctor cmd/subcmd via BaseOidbWorker::DoSendOidbReq;
field tags from the per-feature EncodeRequest). All uin-form OIDB (envelope
reserved=1, matching the NT worker flag=1). One commit for easy rollback.
New OIDB services + byte-oracle tests (fixed-wire, mutation-resistant):
- 0x9130_0 getBuddyRecommendContactArkJson → share_peer/send_ark_share (user)
- 0x8b7_5 getGroupRecommendContactArkJson → share_peer/send_ark_share (group),
share_group_ex/send_group_ark_share (NapCat's getArkJsonGroupShare
was NOT RE'd; routed to this confident equivalent — documented)
- 0xd69_0 getDoubtBuddyReq → get_doubt_friends_add_request
- 0xd69_0 approvalDoubtBuddyReq → set_doubt_friends_add_request (approve only)
- 0xf00_3 modifyGroupExtInfoV2 → set_group_robot_add_option (EXTInfo tags
30/31; GroupExtFilter is client-side gating, not on the wire)
NOT shipped (kernel-.so-side, no static cmd recoverable from this binary —
honest, no guessed packets): get_robot_uin_range (trpc method-routed),
create_collection/get_collection_list (Weiyun multi-step), trans_group_file.
Doubt-list string field NAMES (nick/source/msg) are medium-confidence
(generic serializer); uid+reqTime are high. READ path, so a mislabel is
cosmetic, never a wire/ban risk. Wired through bridge friend/contacts/
groupAdmin apis; proto-defs + per-file subpath exports registered.
This commit is contained in:
21 files changed
+931
No files matched your search
@@ -6,6 +6,8 @@ import { FetchGroupMemberListPage } from '@snowluma/protocol/oidb-services/conta
|
||||
import { FetchGroupRequests } from '@snowluma/protocol/oidb-services/contacts/fetch-group-requests';
|
||||
import { FetchUserProfile } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile';
|
||||
import { FetchUserProfileByUid } from '@snowluma/protocol/oidb-services/contacts/fetch-user-profile-by-uid';
|
||||
import { GetBuddyRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-buddy-recommend-ark';
|
||||
import { GetGroupRecommendArk } from '@snowluma/protocol/oidb-services/contacts/get-group-recommend-ark';
|
||||
import type {
|
||||
FriendInfo,
|
||||
GroupMemberInfo,
|
||||
@@ -66,6 +68,16 @@ export class ContactsApi {
|
||||
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
/** Server-built ARK share card (JSON string) recommending a friend. */
|
||||
getBuddyRecommendArk(userId: number, phoneNumber = ''): Promise<string> {
|
||||
return GetBuddyRecommendArk.invoke(this.ctx, { userId, phoneNumber });
|
||||
}
|
||||
|
||||
/** Server-built ARK share card (JSON string) recommending a group. */
|
||||
getGroupRecommendArk(groupId: number): Promise<string> {
|
||||
return GetGroupRecommendArk.invoke(this.ctx, { groupId });
|
||||
}
|
||||
|
||||
async fetchFriendList(): Promise<FriendInfo[]> {
|
||||
const friends: FriendInfo[] = [];
|
||||
let nextUin: number | null = null;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { ApproveDoubtBuddyReq } from '@snowluma/protocol/oidb-services/friend/approve-doubt-buddy-req';
|
||||
import { DeleteFriend } from '@snowluma/protocol/oidb-services/friend/delete-friend';
|
||||
import { GetDoubtBuddyReq, type DoubtBuddyRequest } from '@snowluma/protocol/oidb-services/friend/get-doubt-buddy-req';
|
||||
import { HandleFriendRequest } from '@snowluma/protocol/oidb-services/friend/handle-friend-request';
|
||||
import { SetFriendRemark } from '@snowluma/protocol/oidb-services/friend/set-friend-remark';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
export type { DoubtBuddyRequest };
|
||||
|
||||
export class FriendApi {
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
@@ -26,4 +30,14 @@ export class FriendApi {
|
||||
setRemark(userId: number, remark: string): Promise<void> {
|
||||
return SetFriendRemark.invoke(this.ctx, { userId, remark });
|
||||
}
|
||||
|
||||
/** List doubtful friend-add requests (可能认识的人). */
|
||||
getDoubtRequests(count: number): Promise<DoubtBuddyRequest[]> {
|
||||
return GetDoubtBuddyReq.invoke(this.ctx, { count });
|
||||
}
|
||||
|
||||
/** Approve a doubtful friend-add request by its uid (the list item's flag). */
|
||||
approveDoubtRequest(uid: string): Promise<void> {
|
||||
return ApproveDoubtBuddyReq.invoke(this.ctx, { uid });
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,17 @@ import { SetGroupRemark } from '@snowluma/protocol/oidb-services/group-admin/set
|
||||
import { SetMemberCard } from '@snowluma/protocol/oidb-services/group-admin/set-member-card';
|
||||
import { SetSearch } from '@snowluma/protocol/oidb-services/group-admin/set-search';
|
||||
import { SetSpecialTitle } from '@snowluma/protocol/oidb-services/group-admin/set-special-title';
|
||||
import { ModifyGroupExtInfo } from '@snowluma/protocol/oidb-services/group-admin/modify-group-ext-info';
|
||||
import type { BridgeContext } from '../bridge-context';
|
||||
|
||||
export class GroupAdminApi {
|
||||
constructor(private readonly ctx: BridgeContext) { }
|
||||
|
||||
/** Set the group's robot-add option (switch / examine) via group ext-info. */
|
||||
setRobotAddOption(groupId: number, robotMemberSwitch?: number, robotMemberExamine?: number): Promise<void> {
|
||||
return ModifyGroupExtInfo.invoke(this.ctx, { groupId, robotMemberSwitch, robotMemberExamine });
|
||||
}
|
||||
|
||||
muteMember(groupId: number, userId: number, duration: number): Promise<void> {
|
||||
return MuteMember.invoke(this.ctx, { groupId, userId, duration });
|
||||
}
|
||||
|
||||
@@ -978,6 +978,155 @@ export const actions = [
|
||||
},
|
||||
}),
|
||||
|
||||
// ─── TierB ③: RE'd OIDB-backed actions (self-constructed packets) ───
|
||||
// Recovered from QQNT wrapper.linux.node via IDA (no NapCat packet wire
|
||||
// existed to port). All low-frequency/benign ops. See each OIDB service
|
||||
// file for the cmd + protobuf provenance.
|
||||
|
||||
// share_peer / send_ark_share — get a "recommend contact" Ark card for a
|
||||
// friend (0x9130_0) or group (0x8b7_5). NapCat's SharePeerBase routes by
|
||||
// which id is present; we mirror that. Returns the server-built ark JSON.
|
||||
defineAction({
|
||||
name: 'share_peer',
|
||||
summary: '分享用户/群 Ark 卡片',
|
||||
readOnly: true,
|
||||
params: {
|
||||
user_id: f.uint().optional(),
|
||||
group_id: f.uint().optional(),
|
||||
phone_number: f.string().default(''),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
if (p.group_id) {
|
||||
return okResponse({ arkMsg: await ctx.bridge.apis.contacts.getGroupRecommendArk(p.group_id) });
|
||||
}
|
||||
if (p.user_id) {
|
||||
return okResponse({ arkMsg: await ctx.bridge.apis.contacts.getBuddyRecommendArk(p.user_id, p.phone_number) });
|
||||
}
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id or group_id is required');
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
defineAction({
|
||||
name: 'send_ark_share',
|
||||
summary: '分享用户/群 Ark 卡片(NapCat 标准名)',
|
||||
readOnly: true,
|
||||
params: {
|
||||
user_id: f.uint().optional(),
|
||||
group_id: f.uint().optional(),
|
||||
phone_number: f.string().default(''),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
if (p.group_id) {
|
||||
return okResponse({ arkMsg: await ctx.bridge.apis.contacts.getGroupRecommendArk(p.group_id) });
|
||||
}
|
||||
if (p.user_id) {
|
||||
return okResponse({ arkMsg: await ctx.bridge.apis.contacts.getBuddyRecommendArk(p.user_id, p.phone_number) });
|
||||
}
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id or group_id is required');
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
// share_group_ex / send_group_ark_share — group-only Ark share. NapCat uses
|
||||
// a distinct kernel API (getArkJsonGroupShare) we did NOT RE; we route to
|
||||
// the fully-RE'd group recommend-contact ark (0x8b7_5), the closest
|
||||
// confident equivalent. The card may differ slightly from NapCat's.
|
||||
defineAction({
|
||||
name: 'share_group_ex',
|
||||
summary: '分享群 Ark 卡片',
|
||||
readOnly: true,
|
||||
params: { group_id: f.uint() },
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
return okResponse(await ctx.bridge.apis.contacts.getGroupRecommendArk(p.group_id));
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
defineAction({
|
||||
name: 'send_group_ark_share',
|
||||
summary: '分享群 Ark 卡片(NapCat 标准名)',
|
||||
readOnly: true,
|
||||
params: { group_id: f.uint() },
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
return okResponse(await ctx.bridge.apis.contacts.getGroupRecommendArk(p.group_id));
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
// get_doubt_friends_add_request — list 可能认识的人 / 被过滤好友申请 (0xd69_0).
|
||||
// The list item's `uid` is what set_doubt_friends_add_request takes as flag.
|
||||
defineAction({
|
||||
name: 'get_doubt_friends_add_request',
|
||||
summary: '获取可疑好友申请',
|
||||
readOnly: true,
|
||||
params: { count: f.int({ min: 0 }).default(50) },
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
const list = await ctx.bridge.apis.friend.getDoubtRequests(p.count);
|
||||
return okResponse(list);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
// set_doubt_friends_add_request — approve a 可疑好友申请 (0xd69_0). `flag` is
|
||||
// the uid from the get list. NapCat only supports approve (no reject path).
|
||||
defineAction({
|
||||
name: 'set_doubt_friends_add_request',
|
||||
summary: '处理可疑好友申请',
|
||||
params: {
|
||||
flag: f.string({ allowEmpty: false }),
|
||||
approve: f.bool().default(true),
|
||||
},
|
||||
run: async (p, ctx) => {
|
||||
// Only approve is RE'd (reject would be a separate delDoubtBuddyReq cmd
|
||||
// we haven't recovered). Reject explicitly rather than silently approve
|
||||
// — accepting approve:false then approving anyway would be the opposite
|
||||
// of the caller's intent.
|
||||
if (!p.approve) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'rejecting a doubt request (delDoubtBuddyReq) is not implemented');
|
||||
}
|
||||
try {
|
||||
await ctx.bridge.apis.friend.approveDoubtRequest(p.flag);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
// set_group_robot_add_option — group robot-add switch/examine via group
|
||||
// ext-info (0xf00_3). Omitted params leave the field unchanged.
|
||||
groupAction({
|
||||
name: 'set_group_robot_add_option',
|
||||
summary: '设置群机器人加群选项',
|
||||
run: async (p, ctx) => {
|
||||
try {
|
||||
await ctx.bridge.apis.groupAdmin.setRobotAddOption(
|
||||
p.group_id, p.robot_member_switch, p.robot_member_examine,
|
||||
);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
},
|
||||
params: {
|
||||
robot_member_switch: f.int({ min: 0 }).optional(),
|
||||
robot_member_examine: f.int({ min: 0 }).optional(),
|
||||
},
|
||||
}),
|
||||
|
||||
defineAction({
|
||||
name: 'get_collection_list',
|
||||
summary: '获取收藏列表(占位)',
|
||||
|
||||
@@ -884,3 +884,78 @@ describe('extended-actions / get_recent_contact stub', () => {
|
||||
expect(res).toMatchObject({ status: 'ok', data: [] });
|
||||
});
|
||||
});
|
||||
|
||||
// ─── TierB ③: RE'd OIDB-backed actions (wiring through handle) ───
|
||||
describe('extended-actions / TierB ③ share + doubt + robot-option', () => {
|
||||
it('share_peer with user_id calls getBuddyRecommendArk and wraps the ark', async () => {
|
||||
const getBuddyRecommendArk = vi.fn(async () => '{"app":"x"}');
|
||||
const bridge = fakeBridge({ apis: { contacts: { getBuddyRecommendArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('share_peer', { user_id: 10000 });
|
||||
expect(getBuddyRecommendArk).toHaveBeenCalledWith(10000, '');
|
||||
expect(res).toMatchObject({ status: 'ok', data: { arkMsg: '{"app":"x"}' } });
|
||||
});
|
||||
|
||||
it('share_peer with group_id calls getGroupRecommendArk', async () => {
|
||||
const getGroupRecommendArk = vi.fn(async () => '{"app":"g"}');
|
||||
const bridge = fakeBridge({ apis: { contacts: { getGroupRecommendArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('share_peer', { group_id: 555 });
|
||||
expect(getGroupRecommendArk).toHaveBeenCalledWith(555);
|
||||
expect(res).toMatchObject({ status: 'ok', data: { arkMsg: '{"app":"g"}' } });
|
||||
});
|
||||
|
||||
it('share_peer with neither id fails', async () => {
|
||||
const res = await makeHandler(fakeCtx(fakeBridge())).handle('share_peer', {});
|
||||
expect(res.status).toBe('failed');
|
||||
});
|
||||
|
||||
it('send_ark_share shares the buddy/group routing', async () => {
|
||||
const getBuddyRecommendArk = vi.fn(async () => 'ARK');
|
||||
const bridge = fakeBridge({ apis: { contacts: { getBuddyRecommendArk } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('send_ark_share', { user_id: 1, phone_number: '99' });
|
||||
expect(getBuddyRecommendArk).toHaveBeenCalledWith(1, '99');
|
||||
expect(res).toMatchObject({ status: 'ok', data: { arkMsg: 'ARK' } });
|
||||
});
|
||||
|
||||
it('share_group_ex / send_group_ark_share return the group ark string', async () => {
|
||||
const getGroupRecommendArk = vi.fn(async () => 'GROUP_ARK');
|
||||
const bridge = fakeBridge({ apis: { contacts: { getGroupRecommendArk } } });
|
||||
for (const name of ['share_group_ex', 'send_group_ark_share']) {
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle(name, { group_id: 42 });
|
||||
expect(res).toMatchObject({ status: 'ok', data: 'GROUP_ARK' });
|
||||
}
|
||||
expect(getGroupRecommendArk).toHaveBeenCalledWith(42);
|
||||
});
|
||||
|
||||
it('get_doubt_friends_add_request returns the mapped list', async () => {
|
||||
const list = [{ uid: 'u1', nick: 'A', source: 's', msg: 'm', reqTime: 123 }];
|
||||
const getDoubtRequests = vi.fn(async () => list);
|
||||
const bridge = fakeBridge({ apis: { friend: { getDoubtRequests } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('get_doubt_friends_add_request', { count: 5 });
|
||||
expect(getDoubtRequests).toHaveBeenCalledWith(5);
|
||||
expect(res).toMatchObject({ status: 'ok', data: list });
|
||||
});
|
||||
|
||||
it('set_doubt_friends_add_request approves by flag (uid)', async () => {
|
||||
const approveDoubtRequest = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { friend: { approveDoubtRequest } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('set_doubt_friends_add_request', { flag: 'u_abc', approve: true });
|
||||
expect(approveDoubtRequest).toHaveBeenCalledWith('u_abc');
|
||||
expect(res).toMatchObject({ status: 'ok' });
|
||||
});
|
||||
|
||||
it('set_doubt_friends_add_request rejects approve:false instead of silently approving', async () => {
|
||||
const approveDoubtRequest = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { friend: { approveDoubtRequest } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('set_doubt_friends_add_request', { flag: 'u_abc', approve: false });
|
||||
expect(res.status).toBe('failed');
|
||||
expect(approveDoubtRequest).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('set_group_robot_add_option forwards group + switch/examine', async () => {
|
||||
const setRobotAddOption = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ apis: { groupAdmin: { setRobotAddOption } } });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('set_group_robot_add_option', { group_id: 12345, robot_member_switch: 1, robot_member_examine: 2 });
|
||||
expect(setRobotAddOption).toHaveBeenCalledWith(12345, 1, 2);
|
||||
expect(res).toMatchObject({ status: 'ok' });
|
||||
});
|
||||
});
|
||||
@@ -59,6 +59,18 @@
|
||||
"types": "./src/oidb-actions/base.ts",
|
||||
"default": "./src/oidb-actions/base.ts"
|
||||
},
|
||||
"./oidb-actions/contact-ark": {
|
||||
"types": "./src/oidb-actions/contact-ark.ts",
|
||||
"default": "./src/oidb-actions/contact-ark.ts"
|
||||
},
|
||||
"./oidb-actions/doubt-buddy": {
|
||||
"types": "./src/oidb-actions/doubt-buddy.ts",
|
||||
"default": "./src/oidb-actions/doubt-buddy.ts"
|
||||
},
|
||||
"./oidb-actions/group-ext": {
|
||||
"types": "./src/oidb-actions/group-ext.ts",
|
||||
"default": "./src/oidb-actions/group-ext.ts"
|
||||
},
|
||||
"./oidb-actions/group-album": {
|
||||
"types": "./src/oidb-actions/group-album.ts",
|
||||
"default": "./src/oidb-actions/group-album.ts"
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Recommend-contact ARK card protobufs, RE'd from QQNT wrapper.linux.node.
|
||||
//
|
||||
// Buddy: OidbSvcTrpcTcp.0x9130_0 (getBuddyRecommendContactArkJson) — encoder
|
||||
// `buddy_recommend_contact_ark_json.cc::EncodeRequest` writes {1:uin,
|
||||
// 2:phone,3:jump_url}; decoder reads {1:ark json}.
|
||||
// Group: OidbSvcTrpcTcp.0x8b7_5 (getGroupRecommendContactArkJson) — encoder
|
||||
// `group_get_ark_json_worker.cc::EncodeRequest` writes {1:reqType=1,
|
||||
// 2:groupCode,5:flag=1}; response (group_info_mgr.cc `[gp_get_ark_json]`)
|
||||
// reads {1:bussness_error_code, 5:ark_json}.
|
||||
// Both return a server-built ark JSON string (the share card payload).
|
||||
|
||||
import type { pb, uint_32 } from '@snowluma/proton';
|
||||
|
||||
export interface OidbBuddyRecommendArkReq {
|
||||
uin?: pb<1, uint_32>;
|
||||
phoneNum?: pb<2, string>;
|
||||
jumpUrl?: pb<3, string>;
|
||||
}
|
||||
export interface OidbBuddyRecommendArkResp {
|
||||
arkJson?: pb<1, string>;
|
||||
}
|
||||
|
||||
export interface OidbGroupRecommendArkReq {
|
||||
reqType?: pb<1, uint_32>;
|
||||
groupCode?: pb<2, uint_32>;
|
||||
flag?: pb<5, uint_32>;
|
||||
}
|
||||
export interface OidbGroupRecommendArkResp {
|
||||
errCode?: pb<1, uint_32>;
|
||||
arkJson?: pb<5, string>;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Doubt-buddy (可能认识的人 / 被过滤的好友申请) protobufs, RE'd from QQNT
|
||||
// wrapper.linux.node. Both get + approval ride OidbSvcTrpcTcp.0xd69_0
|
||||
// (worker ctors both pass cmd=0xd69, sub=0; codec `doubt_codec.cc`).
|
||||
//
|
||||
// GET request (EncodeRequest sub_3F3DC20): {1:const 1, 2:{1:num, 2:uk}}.
|
||||
// reqId is NOT serialized (kernel uses it only for JS callback correlation).
|
||||
// GET response: status (==1 ok) + body{1:repeated item, 2:reason}.
|
||||
// Per-item: uid(1) and reqTime(9,u64) are HIGH confidence (read verbatim
|
||||
// from the codec). The string tags' semantic NAMES (nick/source/msg) come
|
||||
// from the GENERIC buddy serializer registry, not a doubt-specific table,
|
||||
// so they are MEDIUM confidence — but this is a READ, so a mislabel is
|
||||
// cosmetic, never a malformed-packet/ban risk. We model the ones NapCat
|
||||
// surfaces and leave the rest unmapped.
|
||||
// APPROVAL request (EncodeRequest sub_3F3EC90): {1:uid, 2:uid, [3:u32],
|
||||
// [4:str]}. tags 3/4 are emitted only when present; NapCat passes empty
|
||||
// str1/str2, so the approve flow is just {1:uid, 2:uid}.
|
||||
|
||||
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
|
||||
|
||||
export interface OidbDoubtGetReqInner {
|
||||
num?: pb<1, uint_32>;
|
||||
uk?: pb<2, string>;
|
||||
}
|
||||
export interface OidbDoubtGetReq {
|
||||
field1?: pb<1, uint_32>;
|
||||
inner?: pb<2, OidbDoubtGetReqInner>;
|
||||
}
|
||||
|
||||
export interface OidbDoubtItem {
|
||||
uid?: pb<1, string>; // HIGH (kStrTargetUid)
|
||||
nick?: pb<2, string>; // MEDIUM (generic Nick attr 20002)
|
||||
source?: pb<5, string>; // MEDIUM
|
||||
reqTime?: pb<9, uint_64>; // HIGH (attr 60001)
|
||||
msg?: pb<11, string>; // MEDIUM
|
||||
}
|
||||
export interface OidbDoubtGetRespBody {
|
||||
list?: pb_repeated<1, OidbDoubtItem>;
|
||||
reason?: pb<2, string>;
|
||||
}
|
||||
export interface OidbDoubtGetResp {
|
||||
status?: pb<1, uint_32>;
|
||||
body?: pb<2, OidbDoubtGetRespBody>;
|
||||
}
|
||||
|
||||
// tag1 and tag2 come from two DIFFERENT kernel attrs (21503 vs 21001), but
|
||||
// both are uid-class and NapCat sends the same friendUid into both — so the
|
||||
// service sets them to the same value. They are NOT equal by schema design.
|
||||
export interface OidbDoubtApprovalReq {
|
||||
uid?: pb<1, string>;
|
||||
targetUid?: pb<2, string>;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Group ext-info modify (robot-add option), RE'd from QQNT
|
||||
// wrapper.linux.node — OidbSvcTrpcTcp.0xf00_3 (modifyGroupExtInfoV2,
|
||||
// codec `group_ext_list_modify_codec.cc`). Worker ctor sub_4180800 passes
|
||||
// cmd=0xf00, sub=3, flag=1 (uin form).
|
||||
//
|
||||
// Wire (EncodeModifyGroupExtInfoReq sub_4180B80 + ...Params sub_4180980):
|
||||
// ModifyGroupExtInfoReq{ 1:groupCode, 2:GroupExtInfo{ 1:groupCode,
|
||||
// 2:EXTInfo{ 30:inviteRobotMemberSwitch, 31:inviteRobotMemberExamine } } }
|
||||
// The GroupExtFilter that modifyGroupExtInfoV2 takes as its 2nd arg is
|
||||
// CLIENT-SIDE ONLY (it gates which EXTInfo fields the encoder emits); it is
|
||||
// NOT a wire field. So presence of EXTInfo tag 30/31 IS the write signal.
|
||||
// NOTE: proto3 omits zero-valued scalars, so a value of 0 will not transmit;
|
||||
// the robot toggles are non-zero in practice (QQ avoids 0 for set-states).
|
||||
// Response (DecodeModifyGroupExtInfoRsp sub_4180DB0): {1:groupCode, 2:result}.
|
||||
|
||||
import type { pb, int_32, uint_32 } from '@snowluma/proton';
|
||||
|
||||
export interface OidbGroupExtBody {
|
||||
inviteRobotMemberSwitch?: pb<30, uint_32>;
|
||||
inviteRobotMemberExamine?: pb<31, uint_32>;
|
||||
}
|
||||
export interface OidbGroupExtInfo {
|
||||
groupCode?: pb<1, uint_32>;
|
||||
ext?: pb<2, OidbGroupExtBody>;
|
||||
}
|
||||
export interface OidbModifyGroupExtReq {
|
||||
groupCode?: pb<1, uint_32>;
|
||||
info?: pb<2, OidbGroupExtInfo>;
|
||||
}
|
||||
export interface OidbModifyGroupExtResp {
|
||||
groupCode?: pb<1, uint_32>;
|
||||
result?: pb<2, int_32>;
|
||||
}
|
||||
@@ -87,6 +87,26 @@
|
||||
"types": "./src/oidb-services/friend/handle-friend-request.ts",
|
||||
"default": "./src/oidb-services/friend/handle-friend-request.ts"
|
||||
},
|
||||
"./oidb-services/friend/get-doubt-buddy-req": {
|
||||
"types": "./src/oidb-services/friend/get-doubt-buddy-req.ts",
|
||||
"default": "./src/oidb-services/friend/get-doubt-buddy-req.ts"
|
||||
},
|
||||
"./oidb-services/friend/approve-doubt-buddy-req": {
|
||||
"types": "./src/oidb-services/friend/approve-doubt-buddy-req.ts",
|
||||
"default": "./src/oidb-services/friend/approve-doubt-buddy-req.ts"
|
||||
},
|
||||
"./oidb-services/contacts/get-buddy-recommend-ark": {
|
||||
"types": "./src/oidb-services/contacts/get-buddy-recommend-ark.ts",
|
||||
"default": "./src/oidb-services/contacts/get-buddy-recommend-ark.ts"
|
||||
},
|
||||
"./oidb-services/contacts/get-group-recommend-ark": {
|
||||
"types": "./src/oidb-services/contacts/get-group-recommend-ark.ts",
|
||||
"default": "./src/oidb-services/contacts/get-group-recommend-ark.ts"
|
||||
},
|
||||
"./oidb-services/group-admin/modify-group-ext-info": {
|
||||
"types": "./src/oidb-services/group-admin/modify-group-ext-info.ts",
|
||||
"default": "./src/oidb-services/group-admin/modify-group-ext-info.ts"
|
||||
},
|
||||
"./oidb-services/friend/delete-friend": {
|
||||
"types": "./src/oidb-services/friend/delete-friend.ts",
|
||||
"default": "./src/oidb-services/friend/delete-friend.ts"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// 0x9130_0 — getBuddyRecommendContactArkJson: ask the server to build a
|
||||
// "recommend contact" ARK share card for a friend (by uin). Returns the
|
||||
// ark JSON string the card is rendered from. RE'd from QQNT
|
||||
// buddy_recommend_contact_ark_json.cc (EncodeRequest writes uin/phone/jump_url;
|
||||
// DecodeResponse reads field 1 = ark json). uin-form OIDB (envelope reserved=1).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbBuddyRecommendArkReq, OidbBuddyRecommendArkResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace GetBuddyRecommendArk {
|
||||
export const command = 0x9130;
|
||||
export const subCommand = 0;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { userId: number; phoneNumber?: string }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbBuddyRecommendArkReq => ({
|
||||
uin: p.userId,
|
||||
phoneNum: p.phoneNumber ?? '',
|
||||
// Client-side jump_url the kernel hard-codes alongside the uin; the
|
||||
// server echoes it into the card. Mirrors the NT template exactly.
|
||||
jumpUrl: `mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=${p.userId}`,
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbBuddyRecommendArkResp): string => body.arkJson ?? '';
|
||||
|
||||
export const encode = (env: OidbBase<OidbBuddyRecommendArkReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbBuddyRecommendArkReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbBuddyRecommendArkResp> =>
|
||||
protobuf_decode<OidbBase<OidbBuddyRecommendArkResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetBuddyRecommendArk, params);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// 0x8b7_5 — getGroupRecommendContactArkJson: ask the server to build a
|
||||
// "recommend contact" ARK share card for a group (by group code). Returns the
|
||||
// ark JSON string. RE'd from QQNT group_get_ark_json_worker.cc (EncodeRequest
|
||||
// writes {1:reqType=1, 2:groupCode, 5:flag=1}); response read in
|
||||
// group_info_mgr.cc `[gp_get_ark_json]` as {1:bussness_error_code, 5:ark_json}.
|
||||
// uin-form OIDB (envelope reserved=1).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbGroupRecommendArkReq, OidbGroupRecommendArkResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace GetGroupRecommendArk {
|
||||
export const command = 0x8B7;
|
||||
export const subCommand = 5;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { groupId: number }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
// reqType and flag are constants the NT encoder always sends (1 and 1).
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupRecommendArkReq => ({
|
||||
reqType: 1,
|
||||
groupCode: p.groupId,
|
||||
flag: 1,
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbGroupRecommendArkResp): string => body.arkJson ?? '';
|
||||
|
||||
export const encode = (env: OidbBase<OidbGroupRecommendArkReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbGroupRecommendArkReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupRecommendArkResp> =>
|
||||
protobuf_decode<OidbBase<OidbGroupRecommendArkResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<string> =>
|
||||
invokeOidb(deps, GetGroupRecommendArk, params);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 0xd69_0 — approvalDoubtBuddyReq: approve a doubtful friend-add request
|
||||
// (可能认识的人). RE'd from QQNT doubt_codec.cc EncodeRequest sub_3F3EC90:
|
||||
// {1:uid, 2:uid, [3:u32], [4:str]} — tags 3/4 emitted only when present, and
|
||||
// NapCat passes empty str1/str2, so the approve flow is just {1:uid, 2:uid}.
|
||||
// Same OIDB cmd as the getter; the server discriminates by body shape.
|
||||
// uin-form OIDB (envelope reserved=1). NapCat only supports approve (no
|
||||
// reject — rejection would be a separate delDoubtBuddyReq cmd, not RE'd here).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbDoubtApprovalReq } from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace ApproveDoubtBuddyReq {
|
||||
export const command = 0xD69;
|
||||
export const subCommand = 0;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { uid: string }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbDoubtApprovalReq => ({
|
||||
uid: p.uid,
|
||||
targetUid: p.uid,
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
|
||||
|
||||
export const encode = (env: OidbBase<OidbDoubtApprovalReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbDoubtApprovalReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
|
||||
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, ApproveDoubtBuddyReq, params);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// 0xd69_0 — getDoubtBuddyReq: list the "doubtful" friend-add requests
|
||||
// (可能认识的人 / 被过滤的好友申请). RE'd from QQNT doubt_codec.cc.
|
||||
// Request {1:1, 2:{1:num, 2:uk}} (reqId is NOT on the wire). Response body
|
||||
// holds a repeated item list; we surface the fields NapCat exposes.
|
||||
// READ-only: the string field names (nick/source/msg) are MEDIUM confidence
|
||||
// (generic serializer), so a mislabel is cosmetic, never a wire/ban risk.
|
||||
// uid (tag1) and reqTime (tag9) are HIGH confidence.
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbDoubtGetReq, OidbDoubtGetResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface DoubtBuddyRequest {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
|
||||
uid: string;
|
||||
nick: string;
|
||||
source: string;
|
||||
msg: string;
|
||||
reqTime: number;
|
||||
}
|
||||
|
||||
export namespace GetDoubtBuddyReq {
|
||||
export const command = 0xD69;
|
||||
export const subCommand = 0;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params { count: number; cookie?: string }
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbDoubtGetReq => ({
|
||||
field1: 1,
|
||||
inner: { num: p.count, uk: p.cookie ?? '' },
|
||||
});
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbDoubtGetResp): DoubtBuddyRequest[] =>
|
||||
(body.body?.list ?? []).map((it) => ({
|
||||
uid: it.uid ?? '',
|
||||
nick: it.nick ?? '',
|
||||
source: it.source ?? '',
|
||||
msg: it.msg ?? '',
|
||||
reqTime: Number(it.reqTime ?? 0),
|
||||
}));
|
||||
|
||||
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> =>
|
||||
protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
|
||||
invokeOidb(deps, GetDoubtBuddyReq, params);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 0xf00_3 — modifyGroupExtInfoV2, used for set_group_robot_add_option.
|
||||
// RE'd from QQNT group_ext_list_modify_codec.cc:
|
||||
// ModifyGroupExtInfoReq{ 1:groupCode, 2:GroupExtInfo{ 1:groupCode,
|
||||
// 2:EXTInfo{ 30:inviteRobotMemberSwitch, 31:inviteRobotMemberExamine } } }
|
||||
// The NT GroupExtFilter (2nd kernel arg) is client-side only — it just gates
|
||||
// which EXTInfo fields the encoder emits — so we mirror that by only setting
|
||||
// the fields the caller provides. uin-form OIDB (envelope reserved=1).
|
||||
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbModifyGroupExtReq, OidbModifyGroupExtResp, OidbGroupExtBody,
|
||||
} from '@snowluma/proto-defs/oidb-actions/group-ext';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export namespace ModifyGroupExtInfo {
|
||||
export const command = 0xF00;
|
||||
export const subCommand = 3;
|
||||
export const uinForm = true;
|
||||
|
||||
export interface Params {
|
||||
groupId: number;
|
||||
/** undefined → leave unchanged (field not emitted). */
|
||||
robotMemberSwitch?: number;
|
||||
robotMemberExamine?: number;
|
||||
}
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbModifyGroupExtReq => {
|
||||
const ext: OidbGroupExtBody = {};
|
||||
if (p.robotMemberSwitch !== undefined) ext.inviteRobotMemberSwitch = p.robotMemberSwitch;
|
||||
if (p.robotMemberExamine !== undefined) ext.inviteRobotMemberExamine = p.robotMemberExamine;
|
||||
return {
|
||||
groupCode: p.groupId,
|
||||
info: { groupCode: p.groupId, ext },
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: OidbModifyGroupExtResp): void => {
|
||||
// Envelope-level OIDB errors are already thrown by invokeOidb; this is the
|
||||
// body-level ack. 0 (or absent) = success.
|
||||
if (body.result && body.result !== 0) {
|
||||
throw new Error(`modifyGroupExtInfo failed: result=${body.result}`);
|
||||
}
|
||||
};
|
||||
|
||||
export const encode = (env: OidbBase<OidbModifyGroupExtReq>): Uint8Array =>
|
||||
protobuf_encode<OidbBase<OidbModifyGroupExtReq>>(env);
|
||||
|
||||
export const decode = (bytes: Uint8Array): OidbBase<OidbModifyGroupExtResp> =>
|
||||
protobuf_decode<OidbBase<OidbModifyGroupExtResp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps, params: Params): Promise<void> =>
|
||||
invokeOidb(deps, ModifyGroupExtInfo, params);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// Independent protobuf byte-oracle helpers for OIDB service tests.
|
||||
//
|
||||
// These build expected wire bytes from FIRST PRINCIPLES (the RE'd tag
|
||||
// numbers), NOT via proton — so asserting `proton.encode(...) === pb.env(...)`
|
||||
// goes red if a proto-defs field tag is wrong or silently changes. A
|
||||
// symmetric encode→decode round-trip can't catch a tag swap; this can.
|
||||
//
|
||||
// Emission rules mirror proton's observed behaviour: fields in ASCENDING
|
||||
// tag order, and proto3 defaults (0 / '' / false) OMITTED.
|
||||
|
||||
function uvarint(n: number): number[] {
|
||||
const out: number[] = [];
|
||||
let x = n;
|
||||
do {
|
||||
let b = x % 128;
|
||||
x = Math.floor(x / 128);
|
||||
if (x > 0) b |= 0x80;
|
||||
out.push(b);
|
||||
} while (x > 0);
|
||||
return out;
|
||||
}
|
||||
|
||||
function tag(field: number, wire: number): number[] {
|
||||
return uvarint(field * 8 + wire);
|
||||
}
|
||||
|
||||
/** varint field (wire type 0). */
|
||||
export function v(field: number, value: number): number[] {
|
||||
return [...tag(field, 0), ...uvarint(value)];
|
||||
}
|
||||
|
||||
/** length-delimited string field (wire type 2). */
|
||||
export function s(field: number, str: string): number[] {
|
||||
const b = [...Buffer.from(str, 'utf8')];
|
||||
return [...tag(field, 2), ...uvarint(b.length), ...b];
|
||||
}
|
||||
|
||||
/** length-delimited sub-message field (wire type 2). */
|
||||
export function m(field: number, msg: number[]): number[] {
|
||||
return [...tag(field, 2), ...uvarint(msg.length), ...msg];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a body in the OidbBase envelope exactly as proton emits it:
|
||||
* command(1), subCommand(2) [omitted when 0], body(4), reserved(12)=1
|
||||
* [only when uinForm]. errorCode(3)/errorMsg(5) are defaults → omitted.
|
||||
*/
|
||||
export function env(command: number, subCommand: number, body: number[], uinForm: boolean): string {
|
||||
const out = [...v(1, command)];
|
||||
if (subCommand !== 0) out.push(...v(2, subCommand));
|
||||
out.push(...m(4, body));
|
||||
if (uinForm) out.push(...v(12, 1));
|
||||
return Buffer.from(out).toString('hex');
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbBuddyRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetBuddyRecommendArk } from '../../../src/oidb-services/contacts/get-buddy-recommend-ark';
|
||||
import { env, v, s } from '../_pb-oracle';
|
||||
|
||||
function makeSender(arkJson = '{"app":"com.tencent.contact.lua"}') {
|
||||
const respEnv: OidbBase<OidbBuddyRecommendArkResp> = { command: 0x9130, subCommand: 0, body: { arkJson } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbBuddyRecommendArkResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetBuddyRecommendArk namespace', () => {
|
||||
it('declares command 0x9130 sub 0, uin form', () => {
|
||||
expect(GetBuddyRecommendArk.command).toBe(0x9130);
|
||||
expect(GetBuddyRecommendArk.subCommand).toBe(0);
|
||||
expect(GetBuddyRecommendArk.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes uin + the hard-coded jump_url template (phone defaults to empty)', () => {
|
||||
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 5 });
|
||||
expect(out).toMatchObject({ uin: 5, phoneNum: '' });
|
||||
expect(out.jumpUrl).toBe('mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=5');
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0x9130_0 and locks req tags {1:uin, 2:phone, 3:jumpUrl}', async () => {
|
||||
const sender = makeSender();
|
||||
const ark = await GetBuddyRecommendArk.invoke(sender, { userId: 10000 });
|
||||
expect(ark).toBe('{"app":"com.tencent.contact.lua"}');
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x9130_0');
|
||||
const jumpUrl = 'mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=10000';
|
||||
// phoneNum '' is a proto3 default → omitted; only tags 1 + 3 present.
|
||||
const body = [...v(1, 10000), ...s(3, jumpUrl)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x9130, 0, body, true));
|
||||
});
|
||||
|
||||
it('includes phone tag 2 when a phone number is provided', () => {
|
||||
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 7, phoneNumber: '123' });
|
||||
expect(out.phoneNum).toBe('123');
|
||||
});
|
||||
|
||||
it('deserialize returns the ark json string ("" when absent)', () => {
|
||||
expect(GetBuddyRecommendArk.deserialize({} as any, { arkJson: 'x' })).toBe('x');
|
||||
expect(GetBuddyRecommendArk.deserialize({} as any, {})).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbGroupRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetGroupRecommendArk } from '../../../src/oidb-services/contacts/get-group-recommend-ark';
|
||||
import { env, v } from '../_pb-oracle';
|
||||
|
||||
function makeSender(arkJson = '{"app":"com.tencent.structmsg"}') {
|
||||
const respEnv: OidbBase<OidbGroupRecommendArkResp> = { command: 0x8B7, subCommand: 5, body: { errCode: 0, arkJson } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbGroupRecommendArkResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetGroupRecommendArk namespace', () => {
|
||||
it('declares command 0x8B7 sub 5, uin form', () => {
|
||||
expect(GetGroupRecommendArk.command).toBe(0x8B7);
|
||||
expect(GetGroupRecommendArk.subCommand).toBe(5);
|
||||
expect(GetGroupRecommendArk.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes the constant reqType=1 / flag=1 + group code', () => {
|
||||
expect(GetGroupRecommendArk.serialize({} as any, { groupId: 999 })).toEqual({ reqType: 1, groupCode: 999, flag: 1 });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0x8b7_5 and locks req tags {1:reqType, 2:groupCode, 5:flag}', async () => {
|
||||
const sender = makeSender();
|
||||
const ark = await GetGroupRecommendArk.invoke(sender, { groupId: 12345 });
|
||||
expect(ark).toBe('{"app":"com.tencent.structmsg"}');
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0x8b7_5');
|
||||
const body = [...v(1, 1), ...v(2, 12345), ...v(5, 1)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x8B7, 5, body, true));
|
||||
});
|
||||
|
||||
it('deserialize returns the ark json from response field 5', () => {
|
||||
expect(GetGroupRecommendArk.deserialize({} as any, { errCode: 0, arkJson: 'g' })).toBe('g');
|
||||
expect(GetGroupRecommendArk.deserialize({} as any, {})).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { ApproveDoubtBuddyReq } from '../../../src/oidb-services/friend/approve-doubt-buddy-req';
|
||||
import { env, s } from '../_pb-oracle';
|
||||
|
||||
function makeSender() {
|
||||
const respEnv: OidbBase<OidbEmpty> = { command: 0xD69, subCommand: 0, body: {} };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbEmpty>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('ApproveDoubtBuddyReq namespace', () => {
|
||||
it('declares command 0xD69 sub 0, uin form', () => {
|
||||
expect(ApproveDoubtBuddyReq.command).toBe(0xD69);
|
||||
expect(ApproveDoubtBuddyReq.subCommand).toBe(0);
|
||||
expect(ApproveDoubtBuddyReq.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes the uid into both tag 1 and tag 2 (str1/str2 omitted, matching NapCat approve flow)', () => {
|
||||
expect(ApproveDoubtBuddyReq.serialize({} as any, { uid: 'u_x' })).toEqual({ uid: 'u_x', targetUid: 'u_x' });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xd69_0 and locks req tags {1:uid, 2:uid}', async () => {
|
||||
const sender = makeSender();
|
||||
await ApproveDoubtBuddyReq.invoke(sender, { uid: 'u_abc' });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
|
||||
const body = [...s(1, 'u_abc'), ...s(2, 'u_abc')];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbDoubtGetResp } from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { GetDoubtBuddyReq } from '../../../src/oidb-services/friend/get-doubt-buddy-req';
|
||||
import { env, v, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender(): { sendRawPacket: ReturnType<typeof vi.fn> } {
|
||||
const respEnv: OidbBase<OidbDoubtGetResp> = {
|
||||
command: 0xD69, subCommand: 0,
|
||||
body: { status: 1, body: { list: [
|
||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000n },
|
||||
], reason: '' } },
|
||||
};
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbDoubtGetResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('GetDoubtBuddyReq namespace', () => {
|
||||
it('declares command 0xD69 sub 0, uin form', () => {
|
||||
expect(GetDoubtBuddyReq.command).toBe(0xD69);
|
||||
expect(GetDoubtBuddyReq.subCommand).toBe(0);
|
||||
expect(GetDoubtBuddyReq.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('serializes {1:1, 2:{1:count, 2:uk}} (reqId is not on the wire)', () => {
|
||||
expect(GetDoubtBuddyReq.serialize({} as any, { count: 50 })).toEqual({ field1: 1, inner: { num: 50, uk: '' } });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xd69_0 and locks nested req tags {1:const1, 2:{1:num, 2:uk}}', async () => {
|
||||
const sender = makeSender();
|
||||
await GetDoubtBuddyReq.invoke(sender, { count: 50 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
|
||||
// uk '' omitted (proto3 default); inner carries only num.
|
||||
const inner = [...v(1, 50)];
|
||||
const body = [...v(1, 1), ...m(2, inner)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
|
||||
});
|
||||
|
||||
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
|
||||
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
|
||||
expect(list).toEqual([
|
||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000 },
|
||||
]);
|
||||
});
|
||||
|
||||
it('deserialize returns [] when the body has no list', () => {
|
||||
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbModifyGroupExtResp } from '@snowluma/proto-defs/oidb-actions/group-ext';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import { ModifyGroupExtInfo } from '../../../src/oidb-services/group-admin/modify-group-ext-info';
|
||||
import { env, v, m } from '../_pb-oracle';
|
||||
|
||||
function makeSender(result = 0) {
|
||||
const respEnv: OidbBase<OidbModifyGroupExtResp> = { command: 0xF00, subCommand: 3, body: { groupCode: 12345, result } };
|
||||
const r: SendPacketResult = {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbModifyGroupExtResp>>(respEnv)),
|
||||
};
|
||||
return { sendRawPacket: vi.fn(async () => r) };
|
||||
}
|
||||
|
||||
describe('ModifyGroupExtInfo namespace', () => {
|
||||
it('declares command 0xF00 sub 3, uin form', () => {
|
||||
expect(ModifyGroupExtInfo.command).toBe(0xF00);
|
||||
expect(ModifyGroupExtInfo.subCommand).toBe(3);
|
||||
expect(ModifyGroupExtInfo.uinForm).toBe(true);
|
||||
});
|
||||
|
||||
it('only includes the fields the caller provides', () => {
|
||||
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1, robotMemberSwitch: 1 }))
|
||||
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: { inviteRobotMemberSwitch: 1 } } });
|
||||
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1 }))
|
||||
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: {} } });
|
||||
});
|
||||
|
||||
it('byte-oracle: routes to 0xf00_3 and locks nested tags {1:gc,2:{1:gc,2:{30:switch,31:examine}}}', async () => {
|
||||
const sender = makeSender();
|
||||
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 1, robotMemberExamine: 2 });
|
||||
|
||||
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
expect(cmd).toBe('OidbSvcTrpcTcp.0xf00_3');
|
||||
const ext = [...v(30, 1), ...v(31, 2)];
|
||||
const info = [...v(1, 12345), ...m(2, ext)];
|
||||
const body = [...v(1, 12345), ...m(2, info)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
|
||||
});
|
||||
|
||||
it('CAVEAT: a value of 0 is omitted on the wire (proto3 default) — documents the disable edge', async () => {
|
||||
const sender = makeSender();
|
||||
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0 });
|
||||
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
|
||||
// tag 30 varint = 0xF0 0x01; with value 0 it must NOT appear on the wire.
|
||||
expect(Buffer.from(bytes).toString('hex')).not.toContain('f001');
|
||||
});
|
||||
|
||||
it('deserialize throws on a non-zero body result', () => {
|
||||
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 5 })).toThrow(/result=5/);
|
||||
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 0 })).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user