Include optional element.subType and element.summary in the image segment payload (mapped to sub_type and summary) so custom emoji/sticker metadata is preserved. Adds a unit test to verify these fields are forwarded.
event-converter.ts (541 lines) was a class with a 16-case switch
mapping bridge events to OneBot wire JSON, plus a 13-case helper
mapping bridge elements to OneBot segments, plus four lazily-injected
resolver setters (image-url / media-url / message-id / media-segment
sink). Testing one case required instantiating the class and wiring
four setters; 22 of the 29 cases (10 notices + 2 requests + 13 element
types) had zero tests.
This commit kills the class and replaces it with a pure-function
family that takes a ConverterContext (a plain object holding selfId
+ the four resolver callbacks). Each per-event handler becomes a
small typed function that's trivial to call from a test with two
lines of setup.
New layout: packages/core/src/onebot/event-converter/
index.ts 133 ConverterContext + four resolver types +
convertEvent dispatcher + re-exports.
to-message.ts 112 friend / group / temp message (3 handlers)
to-notice.ts 189 group_member_join / leave / mute / admin /
friend_recall / group_recall / friend_poke /
group_poke / group_essence / group_file_upload /
friend_add (11 handlers)
to-request.ts 37 friend_request / group_invite (2 handlers)
to-segment.ts 145 13 element -> segment cases + elementsToJson +
elementsToOneBotSegments
utils.ts 111 parseSelfId / isSameActor / applyMessageIdResolver /
resolveReplyId / segmentsToRawMessage + CQ encoding
Caller migration (3 files, all inside onebot/):
instance.ts: replaces `new EventConverter()` + four setter
calls with a single `converterCtx: ConverterContext`
object built once at construction. The four
closures that used to be passed through setters
are now properties of the context.
instance-context.ts: `eventConverter: EventConverter` field renamed
to `converterCtx: ConverterContext`.
event-pipeline.ts: `ctx.eventConverter.convert(ctx.uin, event)` is
now `convertEvent(ctx.converterCtx, event)`.
External callers (modules/message-actions.ts) keep working unchanged:
elementsToOneBotSegments is re-exported from the new index.ts with
the same signature.
Adds 28 new tests covering every previously-untested case:
message kinds (already partly covered): 7 tests
- friend / group / temp_message peer + self post_type tagging
- messageIdResolver override
notice kinds (new): 11 tests
- all 11 cases, including the sub-type axes
(approve/invite, leave/kick/kick_me, ban/lift_ban,
set/unset, add/delete, etc.)
request kinds (new): 2 tests
- friend_request, group_invite (with sub_type default)
element segments (new): 13 tests
- text / face / image (with + without resolver) / at /
at-all / reply (with + without resolver) / record /
video / json / xml (with + without subType) / file /
mface / poke
mediaSegmentSink wiring (new): 1 test
Plus 3 tests in media-store.test.ts and 1 in event-pipeline.test.ts
adapted to the new API.
317 tests pass (was 285); 3 stability runs, same pre-existing
macOS-arm64 websocket addon failure, unrelated.
Unify per-adapter network configuration into a single `networks` structure and add migration/normalization for legacy on-disk formats. Introduce per-adapter options (messageFormat, reportSelfMessage, enabled, name) and stronger typing in types.ts. Add event-filter utilities to prebuild two serialized payload variants and pick the right one per adapter to avoid repeated JSON.stringify calls. Update HTTP/WS transports to use adapter names/signatures for hot-reload, respect per-adapter options, and improve logging; WS transport also improves client/server lifecycle/reconnect handling. Mark self-sent messages as `message_sent` in the event converter and wire instance dispatch to use the new DispatchPayload. Misc: README edits and accompanying tests added/updated for the refactor.