32 lines
875 B
TypeScript
32 lines
875 B
TypeScript
import { getGroup } from '@/core/data';
|
|
import { OB11Group } from '../../types';
|
|
import { OB11Constructor } from '../../constructor';
|
|
import BaseAction from '../BaseAction';
|
|
import { ActionName } from '../types';
|
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
|
|
const SchemaData = {
|
|
type: 'object',
|
|
properties: {
|
|
group_id: { type: 'number' },
|
|
},
|
|
required: ['group_id']
|
|
} as const satisfies JSONSchema;
|
|
|
|
type Payload = FromSchema<typeof SchemaData>;
|
|
|
|
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
|
|
actionName = ActionName.GetGroupInfo;
|
|
PayloadSchema = SchemaData;
|
|
protected async _handle(payload: Payload) {
|
|
const group = await getGroup(payload.group_id.toString());
|
|
if (group) {
|
|
return OB11Constructor.group(group);
|
|
} else {
|
|
throw `群${payload.group_id}不存在`;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default GetGroupInfo;
|