Add payload and return schemas to OneBot actions (#1549)

* 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.

* Refactor payload schemas to use string IDs

Replaced Type.Union([Type.Number(), Type.String()]) with Type.String for group_id, user_id, and similar fields across all action payload schemas to standardize input types. Also made minor improvements to error handling, return types, and removed unused imports for better code clarity and consistency.

* Refactor type definitions and payload schemas in actions

Standardized type usage and improved type safety across multiple OneBot action files. Updated payload schemas to use string types for IDs and flags, refined return types, and enhanced message content typing. Added error handling for missing parameters in SetGroupTodo.

* Refactor type handling and improve message parsing

Updated several actions to use more precise type casting and type guards, improving type safety and clarity. Enhanced message parsing logic for forward messages and group/friend message history. Standardized return schemas and error handling for avatar and group portrait actions.

* Add napcat-schema package for OpenAPI generation

Introduces the napcat-schema package with scripts and configuration to auto-generate OpenAPI schemas for NapCat OneBot 11 actions. Refactors action handler export in napcat-onebot to support schema extraction.

* Add action examples and enhance action metadata

Introduced a centralized examples.ts file providing payload and return examples for all actions. Updated numerous action classes to include actionDescription, actionTags, payloadExample, and returnExample fields, improving API documentation and discoverability.

* Refactor action example imports and add example files

Moved action example data to dedicated 'examples.ts' files for each action category (extends, file, go-cqhttp, group, msg, system, user). Updated all action classes to import and use the new example modules, improving code organization and maintainability. Also added missing actionTags and actionDescription where appropriate.

* Update GetGroupMemberList.ts

* Add actionSummary and improve action metadata

Introduces the actionSummary property to OneBotAction and updates all action classes to provide concise summaries and improved descriptions. Refactors example imports for better modularity, adds new example files for guild and packet actions, and updates the OpenAPI schema generator to use the new summary and improved descriptions. This enhances API documentation clarity and consistency.

* Enhance action metadata and add examples for new actions

Added actionSummary, actionDescription, and actionTags to multiple OneBot actions for improved API documentation. Introduced payload and response examples for new actions (GetDoubtFriendsAddRequest, SetDoubtFriendsAddRequest) in a new examples.ts file. Also removed unused imports from several files for code clarity.

* Refactor action examples and enhance metadata

Replaced generic ActionExamples imports with more specific examples modules (FileActionsExamples, GroupActionsExamples, GoCQHTTPActionsExamples) across file, group, and go-cqhttp actions. Added or updated actionSummary, actionDescription, actionTags, payloadExample, and returnExample properties for improved API documentation and clarity.

* Refactor extends actions to use new examples module

Replaced imports of ActionExamples with ExtendsActionsExamples in all extends actions. Updated action summary, description, tags, and example references for consistency and clarity across actions. This improves maintainability and aligns with the new examples structure.

* Add action metadata to OneBot action classes

Added or updated actionSummary, actionTags, payloadExample, and returnExample properties for all OneBot action classes in the napcat-onebot package. This improves API documentation and discoverability by providing concise summaries, categorization tags, and usage examples for each action.

* Refactor OpenAPI schema generation to 3.0.1 format

Updated the OpenAPI schema output to use version 3.0.1, restructured tags, responses, and examples for better clarity and compatibility, and simplified output file locations. Also removed unused scripts from package.json.

* Fix SendPokePayloadSchema type definitions

Corrected the type definitions for user_id and target_id to only allow strings, and fixed a syntax error in group_id. This ensures payload validation is consistent and accurate.

Refactor fileset ID API response and schema handling

Updated GetFilesetId action to return a structured object with fileset_id and adjusted its return schema accordingly. Improved frontend TypeBox schema parsing to support allOf (intersection) merging and updated API debug component to construct response schemas in a more robust way for object recognition.

Refactor OneBot API schema handling to use TypeBox

Replaces Zod-based static API schema definitions with dynamic fetching of schemas from the backend using TypeBox. Removes legacy static schema files, updates frontend API debug components to use TypeBox utilities, and adds @sinclair/typebox as a dependency. Backend now exposes a /schemas endpoint for all OneBot actions. Various schema and description fields are updated for clarity and consistency.

* Remove OneBot API navigation list component

Deleted nav_list.tsx from the onebot/api components, removing the OneBotApiNavList React component and its related logic. This may be part of a refactor or cleanup to eliminate unused or redundant UI code.

* Add action tags to OneBot API schema and update tag name

Included the 'tags' property in the OneBot API schema for both backend and frontend, allowing actions to be categorized. Also updated the action tag from '群扩展' to '群组扩展' in SetGroupSign for consistency.

* Add napcat-types package for unified type exports

Introduced the napcat-types package to aggregate and re-export all types, enums, and classes from napcat-core and napcat-onebot. Added external module shims, test files, and configuration for type-only distribution. Updated core and onebot packages to improve export granularity and fixed import paths for better modularity.

* Move external-shims.d.ts to files in tsconfig

external-shims.d.ts was moved from the include array to the files array in tsconfig.json to ensure it is always included explicitly. This change clarifies the intent and may help with TypeScript's file resolution.

Refactor napcat-types package and update plugin deps

Refactored napcat-types to provide more accurate shims, added real type dependencies, and improved build/test scripts. Updated napcat-plugin and napcat-plugin-builtin to depend on napcat-types instead of napcat-onebot. Adjusted imports in affected packages to use napcat-types, and updated pnpm-lock.yaml accordingly.

Add build and test scripts to napcat-types package

Introduced 'build' and 'test' scripts in the napcat-types package.json for easier development and testing. Also updated dependencies in the lockfile.

* 完善部分api描述

* Remove unused statusText constant

Deleted the unused statusText constant from FetchCustomFace.ts to clean up the code.

* Bump napcat-types version to 0.0.2

Updated the package version in package.public.json from 0.0.1 to 0.0.2.

Update napcat-types package metadata and dependencies

Set package as public by changing 'private' to false. Move 'napcat-core' and 'napcat-onebot' from dependencies to devDependencies, and remove 'compressing' from dependencies.

Add public packaging and build script for napcat-types

Introduces package.public.json and a copy-dist.mjs script to automate copying metadata and README into the dist folder for publishing. Updates build script in package.json to use the new copy step. Adds initial package.json and README for napcat-types.

Update scripts in napcat-types package configs

Added a publish script to package.json and removed scripts from package.public.json to streamline configuration and avoid duplication.

* Update publish script to use npm in dist directory

Changed the publish script to run 'npm publish' from the 'dist' directory instead of using 'pnpm publish --filter napcat-types'. This ensures the published package uses the built output.

* Update pnpm-lock.yaml dependencies

Removed 'compressing' from dependencies and cleaned up libc fields for various platform-specific packages. This streamlines the lock file and may improve cross-platform compatibility.

* Add workflow to publish OpenAPI schema to NapCatDocs

Introduces a new 'publish-schema' job in the auto-release workflow. This job builds the napcat-schema package, copies the generated OpenAPI schema to the NapCatDocs repository under a versioned path, and commits the update. Automates schema publishing on release events.

* AI修正部分api文档

* Update OpenAPI version and use dynamic version from napcat-common

Changed OpenAPI spec version to 3.1.0 and replaced the hardcoded API version with napCatVersion from napcat-common. Added napcat-common as a dependency in package.json.

* Update napcat-schema build and OpenAPI version

Renamed the build script from build:schema to build:openapi in napcat-schema and updated the workflow to use the new script. Changed OpenAPI version from 3.1.0 to 3.0.1 in the schema generator. Added napcat-vite as a dependency and integrated its version plugin into the Vite config.

* 暂时OK

* Refactor action examples structure and imports

Moved action example files into a new 'example' directory and updated all imports accordingly. Removed the monolithic 'examples.ts' and redefined ActionExamples in OneBotAction.ts to only include common error codes. This improves code organization and maintainability.

* Fix type for rate limiter middleware in router

Casts the rate limiter middleware to RequestHandler to resolve type compatibility issues with Express router middleware.

* Add OB11 message segment schemas and update SendMsg

Introduces a comprehensive message segment schema (OB11) in a new file, refactors SendMsg payload to use the new OB11MessageMixTypeSchema, and updates related type definitions for improved type safety and extensibility in message handling.

* Refactor OB11 message types to use TypeBox schemas

Migrates all OB11 message segment and message type definitions from interface/enums to TypeBox schemas in types/message.ts. Removes the now-redundant message-segment-schema.ts file and updates imports to use the new schema-based types. This unifies type validation and TypeScript types, improving maintainability and consistency.

---------

Co-authored-by: pohgxz <Ttjonne@outlook.com>
This commit is contained in:
手瓜一十雪andpohgxz authored and GitHub committed 2026-01-27 19:07:17 +08:00
1 parent 791e359199
commit de9d5180fe
213 files changed
+6303 -4395

No files matched your search

+25 -14
View File
@@ -5,23 +5,29 @@ import { ActionName } from '@/napcat-onebot/action/router';
import { OB11MessageImage, OB11MessageVideo } from '@/napcat-onebot/types';
import { Static, Type } from '@sinclair/typebox';
export interface GetFileResponse {
file?: string; // path
url?: string;
file_size?: string;
file_name?: string;
base64?: string;
}
import { FileActionsExamples } from '../example/FileActionsExamples';
const GetFileBase_PayloadSchema = Type.Object({
file: Type.Optional(Type.String()),
file_id: Type.Optional(Type.String()),
export const GetFilePayloadSchema = Type.Object({
file: Type.Optional(Type.String({ description: '文件路径、URL或Base64' })),
file_id: Type.Optional(Type.String({ description: '文件ID' })),
});
export type GetFilePayload = Static<typeof GetFileBase_PayloadSchema>;
export type GetFilePayload = Static<typeof GetFilePayloadSchema>;
export const GetFileReturnSchema = Type.Object({
file: Type.Optional(Type.String({ description: '本地路径' })),
url: Type.Optional(Type.String({ description: '下载URL' })),
file_size: Type.Optional(Type.String({ description: '文件大小' })),
file_name: Type.Optional(Type.String({ description: '文件名' })),
base64: Type.Optional(Type.String({ description: 'Base64编码' })),
}, { description: '文件信息' });
export type GetFileResponse = Static<typeof GetFileReturnSchema>;
export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
override payloadSchema = GetFileBase_PayloadSchema;
override payloadSchema = GetFilePayloadSchema;
override returnSchema = GetFileReturnSchema;
override actionTags = ['文件接口'];
async _handle (payload: GetFilePayload): Promise<GetFileResponse> {
payload.file ||= payload.file_id || '';
@@ -40,12 +46,12 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
let url = '';
if (mixElement?.picElement && rawMessage) {
const tempData =
await this.obContext.apis.MsgApi.rawToOb11Converters.picElement?.(mixElement?.picElement, rawMessage, mixElement, { parseMultMsg: false, disableGetUrl: false, quick_reply: true }) as OB11MessageImage | undefined;
await this.obContext.apis.MsgApi.rawToOb11Converters.picElement?.(mixElement?.picElement, rawMessage, mixElement, { parseMultMsg: false, disableGetUrl: false, quick_reply: true }) as OB11MessageImage | undefined;
url = tempData?.data.url ?? '';
}
if (mixElement?.videoElement && rawMessage) {
const tempData =
await this.obContext.apis.MsgApi.rawToOb11Converters.videoElement?.(mixElement?.videoElement, rawMessage, mixElement, { parseMultMsg: false, disableGetUrl: false, quick_reply: true }) as OB11MessageVideo | undefined;
await this.obContext.apis.MsgApi.rawToOb11Converters.videoElement?.(mixElement?.videoElement, rawMessage, mixElement, { parseMultMsg: false, disableGetUrl: false, quick_reply: true }) as OB11MessageVideo | undefined;
url = tempData?.data.url ?? '';
}
const res: GetFileResponse = {
@@ -113,4 +119,9 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
export default class GetFile extends GetFileBase {
override actionName = ActionName.GetFile;
override actionSummary = '获取文件';
override actionDescription = '获取指定文件的详细信息及下载路径';
override actionTags = ['文件接口'];
override payloadExample = FileActionsExamples.GetFile.payload;
override returnExample = FileActionsExamples.GetFile.response;
}
@@ -3,22 +3,32 @@ import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
file_id: Type.String(),
import { FileActionsExamples } from '../example/FileActionsExamples';
const PayloadSchema = Type.Object({
group_id: Type.String({ description: '群号' }),
file_id: Type.String({ description: '文件ID' }),
});
type Payload = Static<typeof SchemaData>;
type PayloadType = Static<typeof PayloadSchema>;
interface GetGroupFileUrlResponse {
url?: string;
}
const ReturnSchema = Type.Object({
url: Type.Optional(Type.String({ description: '文件下载链接' })),
}, { description: '群文件URL信息' });
export class GetGroupFileUrl extends GetPacketStatusDepends<Payload, GetGroupFileUrlResponse> {
type ReturnType = Static<typeof ReturnSchema>;
export class GetGroupFileUrl extends GetPacketStatusDepends<PayloadType, ReturnType> {
override actionName = ActionName.GOCQHTTP_GetGroupFileUrl;
override payloadSchema = SchemaData;
override payloadSchema = PayloadSchema;
override returnSchema = ReturnSchema;
override actionSummary = '获取群文件URL';
override actionDescription = '获取指定群文件的下载链接';
override actionTags = ['文件接口'];
override payloadExample = FileActionsExamples.GetGroupFileUrl.payload;
override returnExample = FileActionsExamples.GetGroupFileUrl.response;
async _handle (payload: Payload) {
async _handle (payload: PayloadType) {
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
if (contextMsgFile?.fileUUID) {
return {
@@ -1,6 +1,13 @@
import { GetFileBase } from './GetFile';
import { ActionName } from '@/napcat-onebot/action/router';
import { FileActionsExamples } from '../example/FileActionsExamples';
export default class GetImage extends GetFileBase {
override actionName = ActionName.GetImage;
override actionSummary = '获取图片';
override actionDescription = '获取指定图片的信息及路径';
override actionTags = ['文件接口'];
override payloadExample = FileActionsExamples.GetImage.payload;
override returnExample = FileActionsExamples.GetImage.response;
}
@@ -3,21 +3,31 @@ import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
file_id: Type.String(),
import { FileActionsExamples } from '../example/FileActionsExamples';
const PayloadSchema = Type.Object({
file_id: Type.String({ description: '文件ID' }),
});
type Payload = Static<typeof SchemaData>;
type PayloadType = Static<typeof PayloadSchema>;
interface GetPrivateFileUrlResponse {
url?: string;
}
const ReturnSchema = Type.Object({
url: Type.Optional(Type.String({ description: '文件下载链接' })),
}, { description: '私聊文件URL信息' });
export class GetPrivateFileUrl extends GetPacketStatusDepends<Payload, GetPrivateFileUrlResponse> {
type ReturnType = Static<typeof ReturnSchema>;
export class GetPrivateFileUrl extends GetPacketStatusDepends<PayloadType, ReturnType> {
override actionName = ActionName.NapCat_GetPrivateFileUrl;
override payloadSchema = SchemaData;
override payloadSchema = PayloadSchema;
override returnSchema = ReturnSchema;
override actionSummary = '获取私聊文件URL';
override actionDescription = '获取指定私聊文件的下载链接';
override actionTags = ['文件接口'];
override payloadExample = FileActionsExamples.GetPrivateFileUrl.payload;
override returnExample = FileActionsExamples.GetPrivateFileUrl.response;
async _handle (payload: Payload) {
async _handle (payload: PayloadType) {
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id);
if (contextMsgFile?.fileUUID && contextMsgFile.msgId) {
@@ -2,22 +2,35 @@ import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile';
import { ActionName } from '@/napcat-onebot/action/router';
import { promises as fs } from 'fs';
import { FFmpegService } from '@/napcat-core/helper/ffmpeg/ffmpeg';
import { Static, Type } from '@sinclair/typebox';
const out_format = ['mp3', 'amr', 'wma', 'm4a', 'spx', 'ogg', 'wav', 'flac'];
import { FileActionsExamples } from '../example/FileActionsExamples';
type Payload = {
out_format: string;
} & GetFilePayload;
const out_format_list = ['mp3', 'amr', 'wma', 'm4a', 'spx', 'ogg', 'wav', 'flac'];
const PayloadSchema = Type.Object({
file: Type.Optional(Type.String({ description: '文件路径、URL或Base64' })),
file_id: Type.Optional(Type.String({ description: '文件ID' })),
out_format: Type.String({ description: '输出格式' }),
});
type PayloadType = Static<typeof PayloadSchema>;
export default class GetRecord extends GetFileBase {
override actionName = ActionName.GetRecord;
override payloadSchema = PayloadSchema;
override actionSummary = '获取语音';
override actionDescription = '获取指定语音文件的信息,并支持格式转换';
override actionTags = ['文件接口'];
override payloadExample = FileActionsExamples.GetRecord.payload;
override returnExample = FileActionsExamples.GetRecord.response;
override async _handle (payload: Payload): Promise<GetFileResponse> {
const res = await super._handle(payload);
override async _handle (payload: PayloadType): Promise<GetFileResponse> {
const res = await super._handle(payload as GetFilePayload);
if (payload.out_format && typeof payload.out_format === 'string') {
const inputFile = res.file;
if (!inputFile) throw new Error('file not found');
if (!out_format.includes(payload.out_format)) {
if (!out_format_list.includes(payload.out_format)) {
throw new Error('转换失败 out_format 字段可能格式不正确');
}
const outputFile = `${inputFile}.${payload.out_format}`;
@@ -1,6 +1,6 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type, Optional } from '@sinclair/typebox';
import { Static, Type } from '@sinclair/typebox';
import path from 'node:path';
const richMediaList = [
@@ -8,22 +8,31 @@ const richMediaList = [
'.png', '.gif', '.jpg', '.jpeg', '.webp', '.bmp',
];
// 不全部使用json因为:一个文件解析Form-data会变字符串!!! 但是api文档就写List
const SchemaData = Type.Object({
export const CreateFlashTaskPayloadSchema = Type.Object({
files: Type.Union([
Type.Array(Type.String()),
Type.String(),
]),
name: Optional(Type.String()),
thumb_path: Optional(Type.String()),
], { description: '文件列表或单个文件路径' }),
name: Type.Optional(Type.String({ description: '任务名称' })),
thumb_path: Type.Optional(Type.String({ description: '缩略图路径' })),
});
type Payload = Static<typeof SchemaData>;
export type CreateFlashTaskPayload = Static<typeof CreateFlashTaskPayloadSchema>;
export class CreateFlashTask extends OneBotAction<Payload, unknown> {
export class CreateFlashTask extends OneBotAction<CreateFlashTaskPayload, any> {
override actionName = ActionName.CreateFlashTask;
override payloadSchema = SchemaData;
override payloadSchema = CreateFlashTaskPayloadSchema;
override returnSchema = Type.Any({ description: '任务创建结果' });
override actionSummary = '创建闪照任务';
override actionTags = ['文件扩展'];
override payloadExample = {
files: 'C:\\test.jpg',
name: 'test_task'
};
override returnExample = {
task_id: 'task_123'
};
async _handle (payload: Payload) {
async _handle (payload: CreateFlashTaskPayload) {
const fileList = Array.isArray(payload.files) ? payload.files : [payload.files];
let thumbPath: string = '';
@@ -2,17 +2,24 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
export const DownloadFilesetPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type DownloadFilesetPayload = Static<typeof DownloadFilesetPayloadSchema>;
export class DownloadFileset extends OneBotAction<Payload, unknown> {
export class DownloadFileset extends OneBotAction<DownloadFilesetPayload, any> {
override actionName = ActionName.DownloadFileset;
override payloadSchema = SchemaData;
override payloadSchema = DownloadFilesetPayloadSchema;
override returnSchema = Type.Any({ description: '下载结果' });
override actionSummary = '下载文件集';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123'
};
override returnExample = null;
async _handle (payload: Payload) {
async _handle (payload: DownloadFilesetPayload) {
// 默认路径 / fileset_id /为下载路径
return await this.core.apis.FlashApi.downloadFileSetBySetId(payload.fileset_id);
}
@@ -2,19 +2,31 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
share_code: Type.String(),
export const GetFilesetIdPayloadSchema = Type.Object({
share_code: Type.String({ description: '分享码或分享链接' }),
});
type Payload = Static<typeof SchemaData>;
export type GetFilesetIdPayload = Static<typeof GetFilesetIdPayloadSchema>;
export class GetFilesetId extends OneBotAction<Payload, unknown> {
export class GetFilesetId extends OneBotAction<GetFilesetIdPayload, { fileset_id: string }> {
override actionName = ActionName.GetFilesetId;
override payloadSchema = SchemaData;
override payloadSchema = GetFilesetIdPayloadSchema;
override returnSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' })
});
override actionSummary = '获取文件集 ID';
override actionTags = ['文件扩展'];
override payloadExample = {
share_code: '123456'
};
override returnExample = {
fileset_id: 'set_123'
};
async _handle (payload: Payload) {
async _handle (payload: GetFilesetIdPayload) {
// 适配share_link 防止被传 Link无法解析
const code = payload.share_code.includes('=') ? payload.share_code.split('=').slice(1).join('=') : payload.share_code;
return await this.core.apis.FlashApi.fromShareLinkFindSetId(code);
const result = await this.core.apis.FlashApi.fromShareLinkFindSetId(code);
return { fileset_id: result.fileSetId };
}
}
@@ -2,17 +2,27 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
export const GetFilesetInfoPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type GetFilesetInfoPayload = Static<typeof GetFilesetInfoPayloadSchema>;
export class GetFilesetInfo extends OneBotAction<Payload, unknown> {
export class GetFilesetInfo extends OneBotAction<GetFilesetInfoPayload, any> {
override actionName = ActionName.GetFilesetInfo;
override payloadSchema = SchemaData;
override payloadSchema = GetFilesetInfoPayloadSchema;
override returnSchema = Type.Any({ description: '文件集信息' });
override actionSummary = '获取文件集信息';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123'
};
override returnExample = {
fileset_id: 'set_123',
file_list: []
};
async _handle (payload: Payload) {
async _handle (payload: GetFilesetInfoPayload) {
return await this.core.apis.FlashApi.getFileSetIndoBySetId(payload.fileset_id);
}
}
@@ -2,17 +2,29 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
export const GetFlashFileListPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type GetFlashFileListPayload = Static<typeof GetFlashFileListPayloadSchema>;
export class GetFlashFileList extends OneBotAction<Payload, unknown> {
export class GetFlashFileList extends OneBotAction<GetFlashFileListPayload, any> {
override actionName = ActionName.GetFlashFileList;
override payloadSchema = SchemaData;
override payloadSchema = GetFlashFileListPayloadSchema;
override returnSchema = Type.Any({ description: '文件列表' });
override actionSummary = '获取闪照文件列表';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123'
};
override returnExample = [
{
file_name: 'test.jpg',
size: 1024
}
];
async _handle (payload: Payload) {
async _handle (payload: GetFlashFileListPayload) {
return await this.core.apis.FlashApi.getFileListBySetId(payload.fileset_id);
}
}
@@ -2,19 +2,28 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
file_name: Type.Optional(Type.String()),
file_index: Type.Optional(Type.Number()),
export const GetFlashFileUrlPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
file_name: Type.Optional(Type.String({ description: '文件名' })),
file_index: Type.Optional(Type.Number({ description: '文件索引' })),
});
type Payload = Static<typeof SchemaData>;
export type GetFlashFileUrlPayload = Static<typeof GetFlashFileUrlPayloadSchema>;
export class GetFlashFileUrl extends OneBotAction<Payload, unknown> {
export class GetFlashFileUrl extends OneBotAction<GetFlashFileUrlPayload, any> {
override actionName = ActionName.GetFlashFileUrl;
override payloadSchema = SchemaData;
override payloadSchema = GetFlashFileUrlPayloadSchema;
override returnSchema = Type.Any({ description: '文件下载链接' });
override actionSummary = '获取闪照文件链接';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123'
};
override returnExample = {
url: 'http://example.com/flash.jpg'
};
async _handle (payload: Payload) {
async _handle (payload: GetFlashFileUrlPayload) {
// 文件的索引依旧从0开始
return await this.core.apis.FlashApi.getFileTransUrl(payload.fileset_id, {
fileName: payload.file_name,
@@ -2,17 +2,24 @@ import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = Type.Object({
fileset_id: Type.String(),
export const GetShareLinkPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type GetShareLinkPayload = Static<typeof GetShareLinkPayloadSchema>;
export class GetShareLink extends OneBotAction<Payload, unknown> {
export class GetShareLink extends OneBotAction<GetShareLinkPayload, any> {
override actionName = ActionName.GetShareLink;
override payloadSchema = SchemaData;
override payloadSchema = GetShareLinkPayloadSchema;
override returnSchema = Type.Any({ description: '分享链接' });
override actionSummary = '获取文件分享链接';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123'
};
override returnExample = 'http://example.com/share';
async _handle (payload: Payload) {
async _handle (payload: GetShareLinkPayload) {
return await this.core.apis.FlashApi.getShareLinkBySetId(payload.fileset_id);
}
}
@@ -3,19 +3,29 @@ import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox';
import { ChatType, Peer } from 'napcat-core/types';
const SchemaData = Type.Object({
fileset_id: Type.String(),
user_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()])),
export const SendFlashMsgPayloadSchema = Type.Object({
fileset_id: Type.String({ description: '文件集 ID' }),
user_id: Type.Optional(Type.String({ description: '用户 QQ' })),
group_id: Type.Optional(Type.String({ description: '群号' })),
});
type Payload = Static<typeof SchemaData>;
export type SendFlashMsgPayload = Static<typeof SendFlashMsgPayloadSchema>;
export class SendFlashMsg extends OneBotAction<Payload, unknown> {
export class SendFlashMsg extends OneBotAction<SendFlashMsgPayload, any> {
override actionName = ActionName.SendFlashMsg;
override payloadSchema = SchemaData;
override payloadSchema = SendFlashMsgPayloadSchema;
override returnSchema = Type.Any({ description: '发送结果' });
override actionSummary = '发送闪照消息';
override actionTags = ['文件扩展'];
override payloadExample = {
fileset_id: 'set_123',
user_id: '123456789'
};
override returnExample = {
message_id: 123456
};
async _handle (payload: Payload) {
async _handle (payload: SendFlashMsgPayload) {
let peer: Peer;
if (payload.group_id) {
@@ -3,18 +3,26 @@ 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()]),
msg_id: Type.String(),
export const CancelOnlineFilePayloadSchema = Type.Object({
user_id: Type.String({ description: '用户 QQ' }),
msg_id: Type.String({ description: '消息 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type CancelOnlineFilePayload = Static<typeof CancelOnlineFilePayloadSchema>;
export class CancelOnlineFile extends OneBotAction<Payload, unknown> {
export class CancelOnlineFile extends OneBotAction<CancelOnlineFilePayload, any> {
override actionName = ActionName.CancelOnlineFile;
override payloadSchema = SchemaData;
override payloadSchema = CancelOnlineFilePayloadSchema;
override returnSchema = Type.Any({ description: '取消结果' });
override actionSummary = '取消在线文件';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789',
msg_id: '123'
};
override returnExample = null;
async _handle (payload: Payload) {
async _handle (payload: CancelOnlineFilePayload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
@@ -3,17 +3,24 @@ 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()]),
export const GetOnlineFileMessagesPayloadSchema = Type.Object({
user_id: Type.String({ description: '用户 QQ' }),
});
type Payload = Static<typeof SchemaData>;
export type GetOnlineFileMessagesPayload = Static<typeof GetOnlineFileMessagesPayloadSchema>;
export class GetOnlineFileMessages extends OneBotAction<Payload, unknown> {
export class GetOnlineFileMessages extends OneBotAction<GetOnlineFileMessagesPayload, any> {
override actionName = ActionName.GetOnlineFileMessages;
override payloadSchema = SchemaData;
override payloadSchema = GetOnlineFileMessagesPayloadSchema;
override returnSchema = Type.Any({ description: '在线文件消息列表' });
override actionSummary = '获取在线文件消息';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789'
};
override returnExample = [];
async _handle (payload: Payload) {
async _handle (payload: GetOnlineFileMessagesPayload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
@@ -3,19 +3,28 @@ 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()]),
msg_id: Type.String(),
element_id: Type.String(),
export const ReceiveOnlineFilePayloadSchema = Type.Object({
user_id: Type.String({ description: '用户 QQ' }),
msg_id: Type.String({ description: '消息 ID' }),
element_id: Type.String({ description: '元素 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type ReceiveOnlineFilePayload = Static<typeof ReceiveOnlineFilePayloadSchema>;
export class ReceiveOnlineFile extends OneBotAction<Payload, unknown> {
export class ReceiveOnlineFile extends OneBotAction<ReceiveOnlineFilePayload, any> {
override actionName = ActionName.ReceiveOnlineFile;
override payloadSchema = SchemaData;
override payloadSchema = ReceiveOnlineFilePayloadSchema;
override returnSchema = Type.Any({ description: '接收结果' });
override actionSummary = '接收在线文件';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789',
msg_id: '123',
save_path: 'C:\\save'
};
override returnExample = null;
async _handle (payload: Payload) {
async _handle (payload: ReceiveOnlineFilePayload) {
// 默认下载路径
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
@@ -3,19 +3,27 @@ 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()]),
msg_id: Type.String(),
element_id: Type.String(),
export const RefuseOnlineFilePayloadSchema = Type.Object({
user_id: Type.String({ description: '用户 QQ' }),
msg_id: Type.String({ description: '消息 ID' }),
element_id: Type.String({ description: '元素 ID' }),
});
type Payload = Static<typeof SchemaData>;
export type RefuseOnlineFilePayload = Static<typeof RefuseOnlineFilePayloadSchema>;
export class RefuseOnlineFile extends OneBotAction<Payload, unknown> {
export class RefuseOnlineFile extends OneBotAction<RefuseOnlineFilePayload, any> {
override actionName = ActionName.RefuseOnlineFile;
override payloadSchema = SchemaData;
override payloadSchema = RefuseOnlineFilePayloadSchema;
override returnSchema = Type.Any({ description: '拒绝结果' });
override actionSummary = '拒绝在线文件';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789',
msg_id: '123'
};
override returnExample = null;
async _handle (payload: Payload) {
async _handle (payload: RefuseOnlineFilePayload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');
@@ -3,19 +3,28 @@ 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.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: '发送结果' });
override actionSummary = '发送在线文件';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789',
file_path: 'C:\\path\\to\\file.txt',
file_name: 'test.txt'
};
override returnExample = null;
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');
@@ -3,19 +3,27 @@ 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()]),
folder_path: Type.String(),
folder_name: Type.Optional(Type.String()),
export const SendOnlineFolderPayloadSchema = Type.Object({
user_id: Type.String({ description: '用户 QQ' }),
folder_path: Type.String({ description: '本地文件夹路径' }),
folder_name: Type.Optional(Type.String({ description: '文件夹名称 (可选)' })),
});
type Payload = Static<typeof SchemaData>;
export type SendOnlineFolderPayload = Static<typeof SendOnlineFolderPayloadSchema>;
export class SendOnlineFolder extends OneBotAction<Payload, unknown> {
export class SendOnlineFolder extends OneBotAction<SendOnlineFolderPayload, any> {
override actionName = ActionName.SendOnlineFolder;
override payloadSchema = SchemaData;
override payloadSchema = SendOnlineFolderPayloadSchema;
override returnSchema = Type.Any({ description: '发送结果' });
override actionSummary = '发送在线文件夹';
override actionTags = ['文件扩展'];
override payloadExample = {
user_id: '123456789',
folder_path: 'C:\\path\\to\\folder'
};
override returnExample = null;
async _handle (payload: Payload) {
async _handle (payload: SendOnlineFolderPayload) {
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('User not found');