fix: 对齐 OneBot schema 与合并转发消息处理行为 (#1694)

* fix: make defaulted request fields optional

* fix: align onebot schemas with runtime behavior

* fix: tighten schema and unsupported action metadata

* fix: reject empty forward reference ids

* fix: update GoCQHTTPSendForwardMsg to handle messages correctly and adjust payload schema

* fix: refactor message handling in GoCQHTTPSendForwardMsg and add test for message normalization

* fix: update compatibility actions to return appropriate responses and align schemas with runtime behavior

* fix: ensure payload properties are non-null with default values in action handlers

* fix: update StreamStatus comments for clarity and enforce nickname as required in message schema

* fix: integrate sleep function in GetOnlineClient and update tests to verify API call

* fix: add production test checklist for OneBot schema alignment and message handling

* fix: remove outdated production test checklist for OneBot schema alignment
This commit is contained in:
吴天一 authored and GitHub committed 2026-03-12 01:54:33 +08:00
1 parent 8b2207e109
commit deae7fd467
54 files changed
+1078 -195

No files matched your search

@@ -10,12 +10,12 @@ import { GoCQHTTPActionsExamples } from '../example/GoCQHTTPActionsExamples';
const PayloadSchema = Type.Object({
group_id: Type.String({ description: '群号' }),
message_seq: Type.Optional(Type.String({ description: '起始消息序号' })),
count: Type.Number({ default: 20, description: '获取消息数量' }),
reverse_order: Type.Boolean({ default: false, description: '是否反向排序' }),
disable_get_url: Type.Boolean({ default: false, description: '是否禁用获取URL' }),
parse_mult_msg: Type.Boolean({ default: true, description: '是否解析合并消息' }),
quick_reply: Type.Boolean({ default: false, description: '是否快速回复' }),
reverseOrder: Type.Boolean({ default: false, description: '是否反向排序(旧版本兼容)' }),
count: Type.Optional(Type.Number({ default: 20, description: '获取消息数量' })),
reverse_order: Type.Optional(Type.Boolean({ default: false, description: '是否反向排序' })),
disable_get_url: Type.Optional(Type.Boolean({ default: false, description: '是否禁用获取URL' })),
parse_mult_msg: Type.Optional(Type.Boolean({ default: true, description: '是否解析合并消息' })),
quick_reply: Type.Optional(Type.Boolean({ default: false, description: '是否快速回复' })),
reverseOrder: Type.Optional(Type.Boolean({ default: false, description: '是否反向排序(旧版本兼容)' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -37,13 +37,18 @@ export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<PayloadType
override returnExample = GoCQHTTPActionsExamples.GetGroupMsgHistory.response;
async _handle (payload: PayloadType, _adapter: string, config: NetworkAdapterConfig): Promise<ReturnType> {
const count = payload.count!;
const reverseOrder = payload.reverse_order! || payload.reverseOrder!;
const parseMultMsg = payload.parse_mult_msg!;
const disableGetUrl = payload.disable_get_url!;
const quickReply = payload.quick_reply!;
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
const hasMessageSeq = !payload.message_seq ? !!payload.message_seq : !(payload.message_seq?.toString() === '' || payload.message_seq?.toString() === '0');
// 拉取消息
const startMsgId = hasMessageSeq ? (MessageUnique.getMsgIdAndPeerByShortId(+payload.message_seq!)?.MsgId ?? payload.message_seq!.toString()) : '0';
const msgList = hasMessageSeq
? (await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +payload.count, payload.reverse_order || payload.reverseOrder)).msgList
: (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +payload.count)).msgList;
? (await this.core.apis.MsgApi.getMsgHistory(peer, startMsgId, +count, reverseOrder)).msgList
: (await this.core.apis.MsgApi.getAioFirstViewLatestMsgs(peer, +count)).msgList;
if (msgList.length === 0) throw new Error(`消息${payload.message_seq}不存在`);
// 转换序号
await Promise.all(msgList.map(async msg => {
@@ -51,7 +56,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<PayloadType
}));
// 烘焙消息
const ob11MsgList = (await Promise.all(
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat, payload.parse_mult_msg, payload.disable_get_url, payload.quick_reply)))
msgList.map(msg => this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat, parseMultMsg, disableGetUrl, quickReply)))
).filter((msg): msg is OB11Message => msg !== undefined);
return { messages: ob11MsgList };
}