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:
7 files changed
+160
-5
No files matched your search
@@ -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>;
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -601,6 +601,24 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
});
|
||||
|
||||
// DIY status — same wire packet as set_online_status, only the
|
||||
// customExt sub-message is populated and status/extStatus are forced
|
||||
// to the QQ-defined "I have a custom status" values (10 / 2000).
|
||||
// face_id / face_type accept either number or numeric string (napcat
|
||||
// parity); wording is the human-readable text shown next to the icon.
|
||||
h.registerAction('set_diy_online_status', async (params) => {
|
||||
const faceId = asNumber(params.face_id);
|
||||
const faceType = asNumber(params.face_type) || 1;
|
||||
const wording = asString(params.wording);
|
||||
if (!faceId) return failedResponse(RETCODE.BAD_REQUEST, 'face_id is required');
|
||||
try {
|
||||
await ctx.bridge.setDiyOnlineStatus(faceId, wording, faceType);
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
|
||||
// Filtered (机器人/被忽略) group join requests. SnowLuma already
|
||||
// implements the underlying oidb 0x10c8_2 fetch via fetchGroupRequests;
|
||||
// these three actions just rename / project the same data for the
|
||||
|
||||
Reference in new issue
Block a user