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

@@ -2,21 +2,26 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
const PayloadSchema = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()], { description: '群号' }),
});
type Payload = Static<typeof SchemaData>;
interface ResponseType {
can_at_all: boolean;
remain_at_all_count_for_group: number;
remain_at_all_count_for_uin: number;
}
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<Payload, ResponseType> {
override actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
override payloadSchema = SchemaData;
type PayloadType = Static<typeof PayloadSchema>;
async _handle (payload: Payload) {
const ReturnSchema = Type.Object({
can_at_all: Type.Boolean({ description: '是否可以艾特全体' }),
remain_at_all_count_for_group: Type.Number({ description: '群艾特全体剩余次数' }),
remain_at_all_count_for_uin: Type.Number({ description: '个人艾特全体剩余次数' }),
}, { description: '群艾特全体剩余次数' });
type ReturnType = Static<typeof ReturnSchema>;
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<PayloadType, ReturnType> {
override actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
override payloadSchema = PayloadSchema;
override returnSchema = ReturnSchema;
async _handle (payload: PayloadType) {
const ret = await this.core.apis.GroupApi.getGroupRemainAtTimes(payload.group_id.toString());
const data = {
can_at_all: ret.atInfo.canAtAll,