Add payload and return schemas to OneBot actions

Introduced explicit payloadSchema and returnSchema definitions for all OneBotAction classes using @sinclair/typebox. This improves type safety, API documentation, and validation for action payloads and return values. Also refactored method signatures and types for consistency across the codebase.
This commit is contained in:
手瓜一十雪
2026-01-25 14:50:58 +08:00
parent 81e4e54f25
commit b69352f6a1
150 changed files with 2015 additions and 1235 deletions

View File

@@ -1,32 +1,31 @@
import { ContextMode, normalize, ReturnDataType, SendMsgBase } from '@/napcat-onebot/action/msg/SendMsg';
import { OB11PostSendMsg } from '@/napcat-onebot/types';
import { ContextMode, normalize, ReturnDataType, SendMsgBase, SendMsgPayload } from '@/napcat-onebot/action/msg/SendMsg';
import { ActionName } from '@/napcat-onebot/action/router';
// 未验证
export class GoCQHTTPSendForwardMsgBase extends SendMsgBase {
protected override async check (payload: OB11PostSendMsg) {
if (payload.messages) payload.message = normalize(payload.messages);
protected override async check (payload: SendMsgPayload) {
if ((payload as any).messages) payload.message = normalize((payload as any).messages);
return super.check(payload);
}
}
export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
override actionName = ActionName.GoCQHTTP_SendForwardMsg;
protected override async check (payload: OB11PostSendMsg) {
if (payload.messages) payload.message = normalize(payload.messages);
protected override async check (payload: SendMsgPayload) {
if ((payload as any).messages) payload.message = normalize((payload as any).messages);
return super.check(payload);
}
}
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
override async _handle (payload: OB11PostSendMsg): Promise<ReturnDataType> {
override async _handle (payload: SendMsgPayload): Promise<ReturnDataType> {
return this.base_handle(payload, ContextMode.Private);
}
}
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
override async _handle (payload: OB11PostSendMsg): Promise<ReturnDataType> {
override async _handle (payload: SendMsgPayload): Promise<ReturnDataType> {
return this.base_handle(payload, ContextMode.Group);
}
}