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

@@ -1,19 +1,15 @@
import { OneBotAction } from '@/onebot/action/OneBotAction';
import { NTGroupRequestOperateTypes } from '@/core/types';
import { ActionName } from '@/onebot/action/router';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { Static, Type } from '@sinclair/typebox';
const SchemaData = {
type: 'object',
properties: {
flag: { type: 'string' },
approve: { type: ['string', 'boolean'] },
reason: { type: 'string', nullable: true },
},
required: ['flag'],
} as const satisfies JSONSchema;
const SchemaData = Type.Object({
flag: Type.String(),
approve: Type.Optional(Type.Union([Type.Boolean(), Type.String()])),
reason: Type.String({ default: ' ' }),
});
type Payload = FromSchema<typeof SchemaData>;
type Payload = Static<typeof SchemaData>;
export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
actionName = ActionName.SetGroupAddRequest;
@@ -24,7 +20,7 @@ export default class SetGroupAddRequest extends OneBotAction<Payload, null> {
const approve = payload.approve?.toString() !== 'false';
await this.core.apis.GroupApi.handleGroupRequest(flag,
approve ? NTGroupRequestOperateTypes.KAGREE : NTGroupRequestOperateTypes.KREFUSE,
payload.reason ?? ' ',
payload.reason,
);
return null;
}