mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 13:05:09 +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:
@@ -3,20 +3,25 @@ import { GroupNotify, NTGroupRequestOperateTypes } from 'napcat-core/types';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
flag: Type.Union([Type.String(), Type.Number()]),
|
||||
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
|
||||
reason: Type.Optional(Type.Union([Type.String({ default: ' ' }), Type.Null()])),
|
||||
count: Type.Optional(Type.Number({ default: 100 })),
|
||||
const PayloadSchema = Type.Object({
|
||||
flag: Type.Union([Type.String(), Type.Number()], { description: '请求flag' }),
|
||||
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()], { description: '是否同意' })),
|
||||
reason: Type.Optional(Type.Union([Type.String({ default: ' ' }), Type.Null()], { description: '拒绝理由' })),
|
||||
count: Type.Optional(Type.Number({ default: 100, description: '搜索通知数量' })),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
|
||||
const ReturnSchema = Type.Null({ description: '操作结果' });
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export default class SetGroupAddRequest extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.SetGroupAddRequest;
|
||||
override payloadSchema = SchemaData;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
|
||||
async _handle (payload: Payload): Promise<null> {
|
||||
async _handle (payload: PayloadType): Promise<null> {
|
||||
const flag = payload.flag.toString();
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
const reason = payload.reason ?? ' ';
|
||||
|
||||
Reference in New Issue
Block a user