mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 21:10:23 +00:00
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.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { OB11Construct } from '@/napcat-onebot/helper/data';
|
|
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { OB11GroupSchema } from '../schemas';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
group_id: Type.String({ description: '群号' }),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = OB11GroupSchema;
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
class GetGroupInfo extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionName = ActionName.GetGroupInfo;
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
|
|
async _handle (payload: PayloadType) {
|
|
const group = (await this.core.apis.GroupApi.getGroups()).find(e => e.groupCode === payload.group_id.toString());
|
|
if (!group) {
|
|
const data = await this.core.apis.GroupApi.fetchGroupDetail(payload.group_id.toString());
|
|
if (data.ownerUid && data.ownerUin === '0') {
|
|
data.ownerUin = await this.core.apis.UserApi.getUinByUidV2(data.ownerUid);
|
|
}
|
|
return {
|
|
...data,
|
|
group_all_shut: data.shutUpAllTimestamp > 0 ? -1 : 0,
|
|
group_remark: '',
|
|
group_id: +payload.group_id,
|
|
group_name: data.groupName,
|
|
member_count: data.memberNum,
|
|
max_member_count: data.maxMemberNum,
|
|
};
|
|
}
|
|
return OB11Construct.group(group);
|
|
}
|
|
}
|
|
|
|
export default GetGroupInfo;
|