Refactor OneBot networks and event dispatch

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.
This commit is contained in:
手瓜一十雪 committed 2026-05-07 16:01:28 +08:00
1 parent 19a564991c
commit 2a4ca46a99
14 files changed
+1732 -758

No files matched your search

+9 -3
View File
@@ -29,12 +29,14 @@ export class EventConverter {
switch (event.kind) {
case 'friend_message':
{
const isSelf = event.senderUin === selfId;
const postType = isSelf ? 'message_sent' : 'message';
const messageId = this.resolveMessageId(false, event.senderUin, event.msgSeq, PRIVATE_MESSAGE_EVENT);
const segments = await elementsToJson(event.elements, false, event.senderUin, this.imageUrlResolver_, this.mediaUrlResolver_, this.messageIdResolver_);
return {
time: event.time,
self_id: selfId,
post_type: 'message',
post_type: postType,
message_type: 'private',
sub_type: 'friend',
message_id: messageId,
@@ -54,12 +56,14 @@ export class EventConverter {
case 'group_message':
{
const isSelf = event.senderUin === selfId;
const postType = isSelf ? 'message_sent' : 'message';
const messageId = this.resolveMessageId(true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT);
const segments = await elementsToJson(event.elements, true, event.groupId, this.imageUrlResolver_, this.mediaUrlResolver_, this.messageIdResolver_);
return {
time: event.time,
self_id: selfId,
post_type: 'message',
post_type: postType,
message_type: 'group',
sub_type: 'normal',
message_id: messageId,
@@ -83,12 +87,14 @@ export class EventConverter {
case 'temp_message':
{
const isSelf = event.senderUin === selfId;
const postType = isSelf ? 'message_sent' : 'message';
const messageId = this.resolveMessageId(false, event.senderUin, event.msgSeq, PRIVATE_MESSAGE_EVENT);
const segments = await elementsToJson(event.elements, false, event.senderUin, this.imageUrlResolver_, this.mediaUrlResolver_, this.messageIdResolver_);
return {
time: event.time,
self_id: selfId,
post_type: 'message',
post_type: postType,
message_type: 'private',
sub_type: 'group',
message_id: messageId,