fix(onebot): return profile like user details
Restore the interaction user lists returned by get_profile_like and keep self and other-user lookups consistent with the current client behavior. Resolve missing account identities when needed, surface lookup failures, and update the public action catalog with the completed response shape. Add regression coverage for request selection, response decoding, identity enrichment, and malformed results. Fixes #349
This commit is contained in:
9 files changed
+717
-70
No files matched your search
@@ -53,12 +53,13 @@ export interface OidbSender {
|
||||
* `Pick<BridgeContext, ...>` slices the cmd actually needs.
|
||||
*
|
||||
* One of `subCommand` (static) or `resolveSubCommand` (dynamic from
|
||||
* params) must be present. `resolveSubCommand` wins if both are given.
|
||||
* params and context) must be present. `resolveSubCommand` wins if both
|
||||
* are given.
|
||||
*/
|
||||
export interface OidbCallSpec<TCtx extends OidbSender, TReq, TResp, TParams, TResult> {
|
||||
command: number;
|
||||
subCommand?: number;
|
||||
resolveSubCommand?(params: TParams): number;
|
||||
resolveSubCommand?(params: TParams, ctx: TCtx): number;
|
||||
/** Set OIDB envelope `reserved = 1` (UIN-form variant, see makeOidbEnvelope's isUid). */
|
||||
uinForm?: boolean;
|
||||
/** Override the default `OidbSvcTrpcTcp.0xNNNN_N` wire name. A few
|
||||
@@ -107,7 +108,7 @@ export async function invokeOidb<TCtx extends OidbSender, TReq, TResp, TParams,
|
||||
timeoutMs?: number,
|
||||
): Promise<TResult> {
|
||||
const subCommand = spec.resolveSubCommand
|
||||
? spec.resolveSubCommand(params)
|
||||
? spec.resolveSubCommand(params, ctx)
|
||||
: spec.subCommand!;
|
||||
const reqBody = await spec.serialize(ctx, params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
@@ -163,7 +164,7 @@ export async function buildOidbRequest<TCtx extends OidbSender, TReq, TResp, TPa
|
||||
params: TParams,
|
||||
): Promise<{ wireName: string; bytes: Uint8Array }> {
|
||||
const subCommand = spec.resolveSubCommand
|
||||
? spec.resolveSubCommand(params)
|
||||
? spec.resolveSubCommand(params, ctx)
|
||||
: spec.subCommand!;
|
||||
const reqBody = await spec.serialize(ctx, params);
|
||||
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
|
||||
|
||||
@@ -1,15 +1,40 @@
|
||||
// 0x7ED_12 — fetch QQ "thumbs up" (赞) summary for self or another user.
|
||||
// 0x7ED_12 / 0x7ED_13 — fetch QQ "thumbs up" (赞) details for another
|
||||
// user / self respectively.
|
||||
//
|
||||
// Self lookup needs the bot's own UID, hence the `identity` dependency.
|
||||
// For other users we use `resolveUserUid` to translate the uin first.
|
||||
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x7edReq, Oidb0x7edResp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type {
|
||||
Oidb0x7edReq,
|
||||
Oidb0x7edResp,
|
||||
Oidb0x7edUserInfo,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import { resolveSelfUid } from '../../self-uid';
|
||||
|
||||
export interface ProfileLikeUserInfo {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
uid: string;
|
||||
uin: number;
|
||||
src: number;
|
||||
latestTime: number;
|
||||
count: number;
|
||||
giftCount: number;
|
||||
customId: number;
|
||||
lastCharged: number;
|
||||
bAvailableCnt: number;
|
||||
bTodayVotedCnt: number;
|
||||
nick: string;
|
||||
gender: number;
|
||||
age: number;
|
||||
isFriend: boolean;
|
||||
isvip: boolean;
|
||||
isSvip: boolean;
|
||||
}
|
||||
|
||||
export interface LikeInfo {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
uid: string;
|
||||
@@ -19,7 +44,7 @@ export interface LikeInfo {
|
||||
total_count: number;
|
||||
last_time: number;
|
||||
today_count: number;
|
||||
userInfos: never[];
|
||||
userInfos: ProfileLikeUserInfo[];
|
||||
};
|
||||
voteInfo: {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
@@ -27,13 +52,38 @@ export interface LikeInfo {
|
||||
new_count: number;
|
||||
new_nearby_count: number;
|
||||
last_visit_time: number;
|
||||
userInfos: never[];
|
||||
userInfos: ProfileLikeUserInfo[];
|
||||
};
|
||||
}
|
||||
|
||||
function deserializeUserInfo(
|
||||
ctx: GetLike.Deps,
|
||||
data: Oidb0x7edUserInfo,
|
||||
): ProfileLikeUserInfo {
|
||||
const uid = data.uid;
|
||||
if (!uid) throw new Error('get profile like user uid missing');
|
||||
return {
|
||||
uid,
|
||||
uin: ctx.identity.findUinByUid(uid) ?? 0,
|
||||
src: data.src ?? 0,
|
||||
latestTime: data.latestTime ?? 0,
|
||||
count: data.count ?? 0,
|
||||
giftCount: data.giftCount ?? 0,
|
||||
customId: data.customId ?? 0,
|
||||
lastCharged: data.lastCharged ?? 0,
|
||||
bAvailableCnt: data.availableCount ?? 0,
|
||||
bTodayVotedCnt: data.todayVotedCount ?? 0,
|
||||
nick: data.nick ?? '',
|
||||
gender: data.gender ?? 0,
|
||||
age: data.age ?? 0,
|
||||
isFriend: data.isFriend ?? false,
|
||||
isvip: data.isVip ?? false,
|
||||
isSvip: data.isSvip ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
export namespace GetLike {
|
||||
export const command = 0x7ED;
|
||||
export const subCommand = 12;
|
||||
|
||||
export interface Params {
|
||||
/** Omit / 0 → query self. */
|
||||
@@ -44,39 +94,48 @@ export namespace GetLike {
|
||||
|
||||
export type Deps = OidbSender & Pick<BridgeContext, 'identity' | 'resolveUserUid'>;
|
||||
|
||||
const isSelfQuery = (ctx: Deps, p: Params): boolean =>
|
||||
!p.userId || p.userId === Number(ctx.identity.uin);
|
||||
|
||||
export const resolveSubCommand = (p: Params, ctx: Deps): number =>
|
||||
isSelfQuery(ctx, p) ? 13 : 12;
|
||||
|
||||
export const serialize = async (ctx: Deps, p: Params): Promise<Oidb0x7edReq> => {
|
||||
const targetUid = p.userId
|
||||
? await ctx.resolveUserUid(p.userId)
|
||||
: await resolveSelfUid(ctx);
|
||||
const targetUid = isSelfQuery(ctx, p)
|
||||
? await resolveSelfUid(ctx)
|
||||
: await ctx.resolveUserUid(p.userId!);
|
||||
if (!targetUid) throw new Error('target uid not found');
|
||||
return {
|
||||
targetUid,
|
||||
targetUids: [targetUid],
|
||||
basic: 1,
|
||||
vote: 1,
|
||||
favorite: 1,
|
||||
favorite: 0,
|
||||
userProfile: 1,
|
||||
start: p.start ?? 0,
|
||||
limit: p.limit ?? 10,
|
||||
};
|
||||
};
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0x7edResp): LikeInfo => {
|
||||
export const deserialize = (ctx: Deps, body: Oidb0x7edResp): LikeInfo => {
|
||||
const data = body.userLikeInfos?.[0];
|
||||
if (!data) throw new Error('get profile like info empty');
|
||||
return {
|
||||
uid: data.uid ?? '',
|
||||
time: Number(data.time ?? 0),
|
||||
favoriteInfo: {
|
||||
total_count: data.favoriteInfo?.totalCount || 0,
|
||||
last_time: Number(data.favoriteInfo?.lastTime || 0),
|
||||
today_count: data.favoriteInfo?.newCount || 0,
|
||||
userInfos: [],
|
||||
total_count: data.favoriteInfo?.totalCount ?? 0,
|
||||
last_time: data.favoriteInfo?.lastTime ?? 0,
|
||||
today_count: data.favoriteInfo?.todayCount ?? 0,
|
||||
userInfos: (data.favoriteInfo?.userInfos ?? [])
|
||||
.map(user => deserializeUserInfo(ctx, user)),
|
||||
},
|
||||
voteInfo: {
|
||||
total_count: data.voteInfo?.totalCount || 0,
|
||||
new_count: data.voteInfo?.newCount || 0,
|
||||
new_nearby_count: 0,
|
||||
last_visit_time: Number(data.voteInfo?.lastTime || 0),
|
||||
userInfos: [],
|
||||
total_count: data.voteInfo?.totalCount ?? 0,
|
||||
new_count: data.voteInfo?.newCount ?? 0,
|
||||
new_nearby_count: data.voteInfo?.newNearbyCount ?? 0,
|
||||
last_visit_time: data.voteInfo?.lastVisitTime ?? 0,
|
||||
userInfos: (data.voteInfo?.userInfos ?? [])
|
||||
.map(user => deserializeUserInfo(ctx, user)),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user