mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 16:20: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:
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user