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

@@ -3,19 +3,20 @@ import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType } from 'napcat-core/types';
const SchemaData = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()]),
file_path: Type.String(),
file_name: Type.Optional(Type.String()),
export const SendOnlineFilePayloadSchema = Type.Object({
user_id: Type.Union([Type.Number(), Type.String()], { description: '用户 QQ' }),
file_path: Type.String({ description: '本地文件路径' }),
file_name: Type.Optional(Type.String({ description: '文件名 (可选)' })),
});
type Payload = Static<typeof SchemaData>;
export type SendOnlineFilePayload = Static<typeof SendOnlineFilePayloadSchema>;
export class SendOnlineFile extends OneBotAction<Payload, unknown> {
export class SendOnlineFile extends OneBotAction<SendOnlineFilePayload, any> {
override actionName = ActionName.SendOnlineFile;
override payloadSchema = SchemaData;
override payloadSchema = SendOnlineFilePayloadSchema;
override returnSchema = Type.Any({ description: '发送结果' });
async _handle (payload: Payload) {
async _handle (payload: SendOnlineFilePayload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');