feat(onebot): send saved custom faces with sticker presentation

Resolve saved stickers by resource ID or MD5, support group and private destinations with optional replies, and preserve presentation in upload and message metadata.

Fixes #468
This commit is contained in:
DrSmoothl committed 2026-09-26 16:19:45 +08:00
1 parent e05d3176a2
commit 0cc06b6b5e
12 files changed
+358 -31

No files matched your search

+13 -8
View File
@@ -1,4 +1,6 @@
import { createLogger } from '@snowluma/common/logger';
import { protobuf_encode } from '@snowluma/proton';
import type { NotOnlineImagePbReserve, PicExtBizInfo } from '@snowluma/proto-defs/element';
import type { BridgeContext } from '../bridge-context';
import type { MessageElement } from '../events';
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from './highway-client';
@@ -117,6 +119,15 @@ export async function uploadImageMsgInfo(
): Promise<Uint8Array> {
const log = loggerFor(bridge);
const image = await loadImage(element);
const pic: PicExtBizInfo = {
bizType: image.subType,
textSummary: image.summary,
...(isGroup
? { extData: { subType: image.subType, textSummary: image.summary } }
: { bytesPbReserveC2c: protobuf_encode<NotOnlineImagePbReserve>({
subType: image.subType, summary: image.summary,
}) }),
};
log.debug('uploading %d bytes md5=%s... → %s %s',
image.fileSize,
image.md5Hex.slice(0, 8),
@@ -156,13 +167,7 @@ export async function uploadImageMsgInfo(
}],
compatQmsgSceneType: isGroup ? 2 : 1,
extBizInfo: {
pic: {
bizType: image.subType,
textSummary: image.summary,
...(isGroup
? { reserveTroop: { subType: image.subType } }
: { reserveC2c: { subType: image.subType } }),
},
pic,
video: { bytesPbReserve: new Uint8Array(0) },
ptt: {
bytesReserve: new Uint8Array(0),
@@ -174,5 +179,5 @@ export async function uploadImageMsgInfo(
label: 'image',
});
return finalizeMediaMsgInfo(upload, { bizType: image.subType, textSummary: image.summary });
return finalizeMediaMsgInfo(upload, pic);
}
+8 -13
View File
@@ -11,6 +11,7 @@ import type {
NTV2UploadRespBody,
} from '@snowluma/proto-defs/highway';
import { protobuf_encode } from '@snowluma/proton';
import type { PicExtBizInfo } from '@snowluma/proto-defs/element';
import crypto from 'crypto';
import type { BridgeContext } from '../bridge-context';
import { OidbError } from '../oidb-service';
@@ -342,14 +343,12 @@ async function runNtv2UploadOperation(
/**
* Build the encoded MsgInfo bytes that go inside the outgoing commonElem.
*
* `defaultPic` is the image-only fall-back: image uploads inject
* `bizType` + `textSummary` defaults when the server response omits the
* `pic` ext-biz-info. PTT and video pass `undefined` here — they leave
* pic alone unless the server populates it.
* `requestedPic` carries image presentation for this send, including the
* scene-specific compatibility reserve. PTT and video omit it.
*/
export function finalizeMediaMsgInfo(
upload: NTV2UploadRespBody,
defaultPic?: { bizType: number; textSummary: string },
requestedPic?: PicExtBizInfo,
): Uint8Array {
if (!upload?.msgInfo) throw new Error('upload response missing msgInfo');
@@ -358,14 +357,10 @@ export function finalizeMediaMsgInfo(
}));
const extBizInfo: NonNullable<EncodableMediaMsgInfo['extBizInfo']> = {};
if (upload.msgInfo.extBizInfo?.pic) {
extBizInfo.pic = { ...upload.msgInfo.extBizInfo.pic };
if (defaultPic) {
extBizInfo.pic.bizType = extBizInfo.pic.bizType ?? defaultPic.bizType;
extBizInfo.pic.textSummary = extBizInfo.pic.textSummary ?? defaultPic.textSummary;
}
} else if (defaultPic) {
extBizInfo.pic = { bizType: defaultPic.bizType, textSummary: defaultPic.textSummary };
if (upload.msgInfo.extBizInfo?.pic || requestedPic) {
// Upload responses can reuse cached image metadata. Presentation belongs
// to this send, so retain resource metadata but apply the requested style.
extBizInfo.pic = { ...upload.msgInfo.extBizInfo?.pic, ...requestedPic };
}
if (upload.msgInfo.extBizInfo?.video) extBizInfo.video = upload.msgInfo.extBizInfo.video;
if (upload.msgInfo.extBizInfo?.ptt) extBizInfo.ptt = upload.msgInfo.extBizInfo.ptt;