feat(onebot): add set_diy_online_status

DIY online status reuses the existing StatusService.SetStatus wire
call. napcat hardcodes status=10 / extStatus=2000 and threads the
faceId / wording / faceType through a customExt sub-message (field 4
of SetStatus, per napcat packet/transformer/proto/action/action.ts).

Implementation:
- Extend SetStatusReqSchema with optional customExt field. Encoder
  skips undefined fields so the existing set_online_status path stays
  byte-identical on the wire (verified by a new round-trip test).
- New bridge.setDiyOnlineStatus(faceId, wording, faceType) wraps the
  same dispatchSetStatus helper as setOnlineStatus.
- OneBot action set_diy_online_status accepts napcat-style payloads
  (face_id / face_type can be string or number; wording defaults to '').

9 new tests across actions/profile and onebot/extended-actions.
This commit is contained in:
DrSmoothl committed 2026-05-15 19:26:40 +08:00
1 parent ee62f5aa0b
commit f7457e3e59
7 files changed
+160 -5

No files matched your search

+33 -5
View File
@@ -32,11 +32,39 @@ export async function setOnlineStatus(
extStatus: number = 0,
batteryStatus: number = 100,
): Promise<void> {
const request = protoEncode({
status,
extStatus,
batteryStatus,
}, SetStatusReqSchema);
await dispatchSetStatus(bridge, { status, extStatus, batteryStatus });
}
/**
* DIY (custom) online status. napcat fixes status=10 / extStatus=2000
* — the values QQ associates with "I have a custom status string" —
* and threads the faceId / wording / faceType through the customExt
* sub-message of the same SetStatus wire call.
*/
export async function setDiyOnlineStatus(
bridge: Bridge,
faceId: number,
wording: string,
faceType: number,
): Promise<void> {
await dispatchSetStatus(bridge, {
status: 10,
extStatus: 2000,
batteryStatus: 0,
customExt: { faceId, text: wording, faceType },
});
}
async function dispatchSetStatus(
bridge: Bridge,
value: {
status: number;
extStatus: number;
batteryStatus: number;
customExt?: { faceId: number; text: string; faceType: number };
},
): Promise<void> {
const request = protoEncode(value, SetStatusReqSchema);
const result = await bridge.sendRawPacket('trpc.qq_new_tech.status_svc.StatusService.SetStatus', request);
@@ -120,6 +120,7 @@ export interface BridgeInterface {
// ─── Personal profile ───
setOnlineStatus(status: number, extStatus?: number, batteryStatus?: number): Promise<void>;
setDiyOnlineStatus(faceId: number, wording: string, faceType: number): Promise<void>;
setProfile(nickname?: string, personalNote?: string): Promise<void>;
setSelfLongNick(longNick: string): Promise<any>;
setInputStatus(userId: number, eventType: number): Promise<any>;
+4
View File
@@ -85,6 +85,7 @@ import {
} from './actions/friend';
import {
setOnlineStatus as setOnlineStatus_,
setDiyOnlineStatus as setDiyOnlineStatus_,
setProfile as setProfile_,
setSelfLongNick as setSelfLongNick_,
setInputStatus as setInputStatus_,
@@ -503,6 +504,9 @@ export class Bridge implements BridgeInterface {
async setOnlineStatus(status: number, extStatus: number = 0, batteryStatus: number = 100): Promise<void> {
return setOnlineStatus_(this, status, extStatus, batteryStatus);
}
async setDiyOnlineStatus(faceId: number, wording: string, faceType: number): Promise<void> {
return setDiyOnlineStatus_(this, faceId, wording, faceType);
}
async setProfile(nickname?: string, personalNote?: string): Promise<void> {
return setProfile_(this, nickname, personalNote);
}
@@ -861,10 +861,25 @@ export const OidbGetPskeyRespSchema = {
} satisfies ProtoSchema;
// customExt sub-message of SetStatus. Populated only by
// set_diy_online_status (status=10 + extStatus=2000 + this payload);
// regular set_online_status leaves field 4 unset.
//
// Wire (from napcat packet/transformer/proto/action/action.ts SetStatusCustomExt):
// 1 faceId (uint32) — face icon id, e.g. "Q我吧" sticker
// 2 text (string) — wording shown next to the icon
// 3 field3 (uint32) — face_type / template id; observed values 1..3
export const SetStatusCustomExtSchema = {
faceId: { field: 1, type: 'uint32' as const },
text: { field: 2, type: 'string' as const },
faceType: { field: 3, type: 'uint32' as const },
} satisfies ProtoSchema;
export const SetStatusReqSchema = {
status: { field: 1, type: 'int32' as const },
extStatus: { field: 2, type: 'int32' as const },
batteryStatus: { field: 3, type: 'int32' as const },
customExt: { field: 4, type: 'message' as const, schema: SetStatusCustomExtSchema },
} satisfies ProtoSchema;
export const SetStatusRespSchema = {