mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 16:20:25 +00:00
refactor: type-check (#586)
* refactor: type-check * fix: default * refactor: type-check
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
group_id: { type: ['number', 'string'] },
|
||||
group_name: { type: 'string' },
|
||||
},
|
||||
required: ['group_id', 'group_name'],
|
||||
} as const satisfies JSONSchema;
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
group_name: Type.String(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
type Payload = FromSchema<typeof SchemaData>;
|
||||
export default class SetGroupName extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupName;
|
||||
payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
let ret = await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||
const ret = await this.core.apis.GroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||
if (ret.result !== 0) {
|
||||
throw new Error(`设置群名称失败 ErrCode: ${ret.result} ErrMsg: ${ret.errMsg}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user