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

@@ -5,9 +5,9 @@ import { Static, Type } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
group_id: Type.String({ description: '群号' }),
bot_appid: Type.String({ description: '机器人AppID' }),
button_id: Type.String({ default: '', description: '按钮ID' }),
callback_data: Type.String({ default: '', description: '回调数据' }),
msg_seq: Type.String({ default: '10086', description: '消息序列号' }),
button_id: Type.Optional(Type.String({ default: '', description: '按钮ID' })),
callback_data: Type.Optional(Type.String({ default: '', description: '回调数据' })),
msg_seq: Type.Optional(Type.String({ default: '10086', description: '消息序列号' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -35,11 +35,11 @@ export class ClickInlineKeyboardButton extends OneBotAction<PayloadType, ReturnT
async _handle (payload: PayloadType) {
return await this.core.apis.MsgApi.clickInlineKeyboardButton({
buttonId: payload.button_id,
buttonId: payload.button_id!,
peerId: payload.group_id.toString(),
botAppid: payload.bot_appid,
msgSeq: payload.msg_seq,
callback_data: payload.callback_data,
msgSeq: payload.msg_seq!,
callback_data: payload.callback_data!,
dmFlag: 0,
chatType: 2,
});
@@ -3,7 +3,7 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
const PayloadSchema = Type.Object({
count: Type.Union([Type.Number(), Type.String()], { default: 48, description: '获取数量' }),
count: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: 48, description: '获取数量' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -27,7 +27,7 @@ export class FetchCustomFace extends OneBotAction<PayloadType, ReturnType> {
];
async _handle (payload: PayloadType) {
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count);
const ret = await this.core.apis.MsgApi.fetchFavEmojiList(+payload.count!);
return ret.emojiInfoList.map(e => e.url);
}
}
@@ -7,8 +7,8 @@ const PayloadSchema = Type.Object({
message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }),
emojiId: Type.Union([Type.Number(), Type.String()], { description: '表情ID' }),
emojiType: Type.Union([Type.Number(), Type.String()], { description: '表情类型' }),
count: Type.Union([Type.Number(), Type.String()], { default: 20, description: '获取数量' }),
cookie: Type.String({ default: '', description: '分页Cookie' }),
count: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: 20, description: '获取数量' })),
cookie: Type.Optional(Type.String({ default: '', description: '分页Cookie' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -64,7 +64,7 @@ export class FetchEmojiLike extends OneBotAction<PayloadType, ReturnType> {
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
if (!msg) throw new Error('消息不存在');
const res = await this.core.apis.MsgApi.getMsgEmojiLikesList(
msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), payload.cookie, +payload.count
msgIdPeer.Peer, msg.msgSeq, payload.emojiId.toString(), payload.emojiType.toString(), payload.cookie!, +payload.count!
);
return res;
}
@@ -6,7 +6,7 @@ import { ExtendsActionsExamples } from '../example/ExtendsActionsExamples';
const PayloadSchema = Type.Object({
group_id: Type.String({ description: '群号' }),
chat_type: Type.Union([Type.Number(), Type.String()], { default: 1, description: '聊天类型' }),
chat_type: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: 1, description: '聊天类型' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -4,7 +4,7 @@ import { Type, Static } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
category: Type.String({ description: '分类ID' }),
count: Type.String({ default: '50', description: '获取数量' }),
count: Type.Optional(Type.String({ default: '50', description: '获取数量' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -77,6 +77,6 @@ export class GetCollectionList extends OneBotAction<PayloadType, ReturnType> {
};
async _handle (payload: PayloadType) {
return await this.core.apis.CollectionApi.getAllCollection(+payload.category, +payload.count);
return await this.core.apis.CollectionApi.getAllCollection(+payload.category, +payload.count!);
}
}
@@ -9,7 +9,7 @@ const PayloadSchema = Type.Object({
message_id: Type.String({ description: '消息ID,可以传递长ID或短ID' }),
emoji_id: Type.String({ description: '表情ID' }),
emoji_type: Type.Optional(Type.String({ description: '表情类型' })),
count: Type.Number({ default: 0, description: '数量,0代表全部' }),
count: Type.Optional(Type.Number({ default: 0, description: '数量,0代表全部' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -46,6 +46,7 @@ export class GetEmojiLikes extends OneBotAction<PayloadType, ReturnType> {
override returnSchema = ReturnSchema;
async _handle (payload: PayloadType) {
const count = payload.count!;
let peer: Peer;
let msgId: string;
@@ -66,7 +67,7 @@ export class GetEmojiLikes extends OneBotAction<PayloadType, ReturnType> {
const emojiType = payload.emoji_type ?? (payload.emoji_id.length > 3 ? '2' : '1');
const emojiLikeList: Array<{ user_id: string; nick_name: string; }> = [];
let cookie = '';
const needFetchCount = payload.count === 0 ? 200 : Math.ceil(payload.count / 15);
const needFetchCount = count === 0 ? 200 : Math.ceil(count / 15);
for (let page = 0; page < needFetchCount; page++) {
const res = await this.core.apis.MsgApi.getMsgEmojiLikesList(
peer, msg.msgSeq, payload.emoji_id.toString(), emojiType, cookie, 15
@@ -82,8 +83,8 @@ export class GetEmojiLikes extends OneBotAction<PayloadType, ReturnType> {
cookie = res.cookie;
}
// 切断多余部分
if (payload.count > 0) {
emojiLikeList.splice(payload.count);
if (count > 0) {
emojiLikeList.splice(count);
}
return { emoji_like_list: emojiLikeList };
}
@@ -4,8 +4,8 @@ import { Type, Static } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
user_id: Type.Optional(Type.String({ description: 'QQ号' })),
start: Type.Union([Type.Number(), Type.String()], { default: 0, description: '起始位置' }),
count: Type.Union([Type.Number(), Type.String()], { default: 10, description: '获取数量' }),
start: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: 0, description: '起始位置' })),
count: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: 10, description: '获取数量' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -61,10 +61,12 @@ export class GetProfileLike extends OneBotAction<PayloadType, ReturnType> {
};
async _handle (payload: PayloadType): Promise<ReturnType> {
const start = payload.start!;
const count = payload.count!;
const isSelf = this.core.selfInfo.uin === payload.user_id || !payload.user_id;
const userUid = isSelf || !payload.user_id ? this.core.selfInfo.uid : await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
const type = isSelf ? 2 : 1;
const ret = await this.core.apis.UserApi.getProfileLike(userUid ?? this.core.selfInfo.uid, +payload.start, +payload.count, type);
const ret = await this.core.apis.UserApi.getProfileLike(userUid ?? this.core.selfInfo.uid, +start, +count, type);
const data = ret.info.userLikeInfos[0];
if (!data) {
throw new Error('get info error');
@@ -6,7 +6,7 @@ import { Static, Type } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
cmd: Type.String({ description: '命令字' }),
data: Type.String({ description: '十六进制数据' }),
rsp: Type.Union([Type.String(), Type.Boolean()], { default: true, description: '是否等待响应' }),
rsp: Type.Optional(Type.Union([Type.String(), Type.Boolean()], { default: true, description: '是否等待响应' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -4,8 +4,8 @@ import { Static, Type } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
face_id: Type.Union([Type.Number(), Type.String()], { description: '图标ID' }), // 参考 face_config.json 的 QSid
face_type: Type.Union([Type.Number(), Type.String()], { default: '1', description: '图标类型' }),
wording: Type.String({ default: ' ', description: '状态文字内容' }),
face_type: Type.Optional(Type.Union([Type.Number(), Type.String()], { default: '1', description: '图标类型' })),
wording: Type.Optional(Type.String({ default: ' ', description: '状态文字内容' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -30,8 +30,8 @@ export class SetDiyOnlineStatus extends OneBotAction<PayloadType, ReturnType> {
async _handle (payload: PayloadType) {
const ret = await this.core.apis.UserApi.setDiySelfOnlineStatus(
payload.face_id.toString(),
payload.wording,
payload.face_type.toString()
payload.wording!,
payload.face_type!.toString()
);
if (ret.result !== 0) {
throw new Error('设置在线状态失败');
@@ -7,7 +7,6 @@ const PayloadSchema = Type.Object({
album_id: Type.String({ description: '相册ID' }),
lloc: Type.String({ description: '媒体ID (lloc)' }),
id: Type.String({ description: '点赞ID' }), // 421_1_0_1012959257|V61Yiali4PELg90bThrH4Bo2iI1M5Kab|V5bCgAxMDEyOTU5MjU3.PyqaPndPxg!^||^421_1_0_1012959257|V61Yiali4PELg90bThrH4Bo2iI1M5Kab|17560363448^||^1
set: Type.Boolean({ default: true, description: '是否点赞' }), // true=点赞 false=取消点赞 未实现
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -7,7 +7,7 @@ import { ExtendsActionsExamples } from '../example/ExtendsActionsExamples';
const PayloadSchema = Type.Object({
group_id: Type.String({ description: '群号' }),
user_id: Type.String({ description: 'QQ号' }),
special_title: Type.String({ default: '', description: '专属头衔' }),
special_title: Type.Optional(Type.String({ default: '', description: '专属头衔' })),
});
type PayloadType = Static<typeof PayloadSchema>;
@@ -29,6 +29,6 @@ export class SetSpecialTitle extends GetPacketStatusDepends<PayloadType, ReturnT
async _handle (payload: PayloadType) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
await this.core.apis.PacketApi.pkt.operation.SetGroupSpecialTitle(+payload.group_id, uid, payload.special_title);
await this.core.apis.PacketApi.pkt.operation.SetGroupSpecialTitle(+payload.group_id, uid, payload.special_title!);
}
}
@@ -5,7 +5,7 @@ import { Static, Type } from '@sinclair/typebox';
const PayloadSchema = Type.Object({
user_id: Type.Optional(Type.String({ description: 'QQ号' })),
group_id: Type.Optional(Type.String({ description: '群号' })),
phone_number: Type.String({ default: '', description: '手机号' }),
phone_number: Type.Optional(Type.String({ default: '', description: '手机号' })),
});
type PayloadType = Static<typeof PayloadSchema>;