feat(onebot): unify market faces to image segments + add send support

Market faces (商城表情) now decode to an OneBot `image` segment carrying
NapCat-style markers (emoji_id/emoji_package_id/key/summary) plus a gxh
gif URL, so clients that don't special-case `mface` still render the
sticker while aware clients can reproduce it.

Adds the previously-missing send path: a dedicated `mface` segment OR an
`image` segment carrying `emoji_id` rebuilds the wire `marketFace`
(faceId=hex(emoji_id), itemType 6 / subType 3 / 300×300 /
pbReserve.field8=1) — byte-matched against NapCat and Lagrange.Core.

- proto-defs: MarketFace.key bytes→string; +MarketFacePbReserve{field8@8}
- protocol: decode faceId→emojiId(hex)/tabId/key; makeMarketFaceElem +
  buildSendElems 'mface' case; format preview keeps the sticker name
- onebot: to-segment mface→image; message-parser mface + image(emoji_id)
- tests: wire decode + full proton round-trip; parse→build; segment shape

Reply/forward round-trips preserved (element keeps type 'mface' + text).
This commit is contained in:
DrSmoothl committed 2026-06-14 20:47:50 +08:00
1 parent 58c02d415f
commit 8dc4ff48f8
10 files changed
+247 -16

No files matched your search

@@ -127,12 +127,27 @@ async function elementToSegment(
}
if (element.type === 'mface') {
// Unify market faces (商城表情) to an `image` segment so OneBot clients
// that don't special-case `mface` still render the sticker, while the
// `emoji_id`/`emoji_package_id`/`key` markers let aware clients (and our
// own send path) reproduce it as a real market face. Mirrors NapCat's
// marketFaceElement → image conversion. The gxh URL is a self-contained
// external link (no rkey), so we set it directly and skip mediaSegmentSink.
const emojiId = element.emojiId ?? '';
const dir = emojiId.slice(0, 2);
const url = emojiId
? `https://gxh.vip.qq.com/club/item/parcel/item/${dir}/${emojiId}/raw300.gif`
: '';
return {
type: 'mface',
type: 'image',
data: {
name: element.text ?? '',
tab_id: element.faceId ?? 0,
sub_type: element.subType ?? 0,
file: emojiId ? `${dir}-${emojiId}.gif` : '',
url,
summary: element.text ?? '',
sub_type: 0,
emoji_id: emojiId,
emoji_package_id: element.emojiPackageId ?? 0,
key: element.emojiKey ?? '',
},
};
}