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

+12 -1
View File
@@ -85,6 +85,14 @@ export interface TransElem {
elemValue?: pb<2, bytes>;
}
// MarketFace.pbReserve(13) inner message. NapCat/Lagrange set field8=1 on
// send (marks the sticker as a "magic"/animated face). We encode it via
// protobuf_encode<MarketFacePbReserve> into the bytes field — same pattern as
// the mention pbReserve in element-builder.makeMentionElem.
export interface MarketFacePbReserve {
field8?: pb<8, uint_32>;
}
export interface MarketFace {
faceName?: pb<1, string>;
itemType?: pb<2, uint_32>;
@@ -92,7 +100,10 @@ export interface MarketFace {
faceId?: pb<4, bytes>;
tabId?: pb<5, uint_32>;
subType?: pb<6, uint_32>;
key?: pb<7, bytes>;
// `key` is a short ASCII token (e.g. "0"); Lagrange.Core and NapCat both
// type it as a string. Kept as string so it round-trips verbatim through
// the receive→`emoji_id` marker→re-send path without a bytes/utf8 hop.
key?: pb<7, string>;
param?: pb<8, bytes>;
mediaType?: pb<9, uint_32>;
imageWidth?: pb<10, uint_32>;