mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 08:10:25 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user