refactor: type-check (#586)

* refactor: type-check

* fix: default

* refactor: type-check
This commit is contained in:
手瓜一十雪
2024-12-01 12:41:51 +08:00
committed by GitHub
parent fa78e6567c
commit fb3370ccf9
83 changed files with 566 additions and 943 deletions

View File

@@ -3,22 +3,18 @@ import { ActionName } from '@/onebot/action/router';
import { ChatType, Peer } from '@/core/types';
import fs from 'fs';
import { uri2local } from '@/common/file';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageContext } from '@/onebot/api';
import { SendMessageContext } from '@/onebot/api';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['number', 'string'] },
file: { type: 'string' },
name: { type: 'string' },
folder: { type: 'string' },
folder_id: { type: 'string' },//临时扩展
},
required: ['group_id', 'file', 'name'],
} as const satisfies JSONSchema;
const SchemaData = Type.Object({
group_id: Type.Union([Type.Number(), Type.String()]),
file: Type.String(),
name: Type.String(),
folder: Type.Optional(Type.String()),
folder_id: Type.Optional(Type.String()),//临时扩展
});
type Payload = FromSchema<typeof SchemaData>;
type Payload = Static<typeof SchemaData>;
export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null> {
actionName = ActionName.GoCQHTTP_UploadGroupFile;
@@ -37,7 +33,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null>
if (!downloadResult.success) {
throw new Error(downloadResult.errMsg);
}
const msgContext: MessageContext = {
const msgContext: SendMessageContext = {
peer: peer,
deleteAfterSentFiles: []
};