diff --git a/src/onebot11/action/go-cqhttp/UploadGroupFile.ts b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts index 32f5207d..224af213 100644 --- a/src/onebot11/action/go-cqhttp/UploadGroupFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts @@ -6,17 +6,23 @@ import { ChatType, SendFileElement } from '@/core/entities'; import fs from 'fs'; import { NTQQMsgApi } from '@/core/apis/msg'; import { uri2local } from '@/common/utils/file'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + file: { type: 'string' }, + name: { type: 'string' }, + folder: { type: 'string' } + }, + required: ['group_id', 'file', 'name', 'folder'] +} as const satisfies JSONSchema; -interface Payload { - group_id: number; - file: string; - name: string; - folder: string; -} +type Payload = FromSchema; export default class GoCQHTTPUploadGroupFile extends BaseAction { actionName = ActionName.GoCQHTTP_UploadGroupFile; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const group = await getGroup(payload.group_id.toString()); if (!group) { diff --git a/src/onebot11/action/group/GetGroupEssence.ts b/src/onebot11/action/group/GetGroupEssence.ts index 3f0bc9dd..58bda81a 100644 --- a/src/onebot11/action/group/GetGroupEssence.ts +++ b/src/onebot11/action/group/GetGroupEssence.ts @@ -5,16 +5,23 @@ import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQMsgApi } from '@/core/apis/msg'; import { GroupEssenceMsgRet, WebApi } from '@/core/apis/webapi'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface PayloadType { - group_id: number; - pages: number; -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + pages: { type: 'number' }, + }, + required: ['group_id', 'pages'] +} as const satisfies JSONSchema; -export class GetGroupEssence extends BaseAction { +type Payload = FromSchema; + +export class GetGroupEssence extends BaseAction { actionName = ActionName.GoCQHTTP_GetEssenceMsg; - - protected async _handle(payload: PayloadType) { + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { const ret = await WebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString()); if (!ret) { throw new Error('获取失败'); diff --git a/src/onebot11/action/group/GetGroupInfo.ts b/src/onebot11/action/group/GetGroupInfo.ts index 2f6a3cc3..ed3af013 100644 --- a/src/onebot11/action/group/GetGroupInfo.ts +++ b/src/onebot11/action/group/GetGroupInfo.ts @@ -3,15 +3,22 @@ import { OB11Group } from '../../types'; import { OB11Constructor } from '../../constructor'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface PayloadType { - group_id: number -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + }, + required: ['group_id'] +} as const satisfies JSONSchema; -class GetGroupInfo extends BaseAction { +type Payload = FromSchema; + +class GetGroupInfo extends BaseAction { actionName = ActionName.GetGroupInfo; - - protected async _handle(payload: PayloadType) { + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { const group = await getGroup(payload.group_id.toString()); if (group) { return OB11Constructor.group(group); diff --git a/src/onebot11/action/group/GetGroupList.ts b/src/onebot11/action/group/GetGroupList.ts index 6d6bdc92..8a1eefd5 100644 --- a/src/onebot11/action/group/GetGroupList.ts +++ b/src/onebot11/action/group/GetGroupList.ts @@ -6,17 +6,23 @@ import { groups } from '@/core/data'; import { NTQQGroupApi } from '@/core/apis'; import { Group } from '@/core/entities'; import { log } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +// no_cache get时传字符串 +const SchemaData = { + type: 'object', + properties: { + no_cache: { type: 'boolean' }, + } +} as const satisfies JSONSchema; -interface Payload { - no_cache: boolean | string; -} +type Payload = FromSchema; class GetGroupList extends BaseAction { actionName = ActionName.GetGroupList; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { let groupList: Group[] = Array.from(groups.values()); - if (groupList.length === 0 || payload?.no_cache === true || payload?.no_cache === 'true') { + if (groupList.length === 0 || payload?.no_cache === true /*|| payload.no_cache === 'true'*/) { groupList = await NTQQGroupApi.getGroups(true); // log('get groups', groups); } diff --git a/src/onebot11/action/group/GetGroupMemberInfo.ts b/src/onebot11/action/group/GetGroupMemberInfo.ts index f9ae9901..9a68cdb0 100644 --- a/src/onebot11/action/group/GetGroupMemberInfo.ts +++ b/src/onebot11/action/group/GetGroupMemberInfo.ts @@ -8,24 +8,31 @@ import { log, logDebug } from '@/common/utils/log'; import { isNull } from '../../../common/utils/helper'; import { WebApi } from '@/core/apis/webapi'; import { NTQQGroupApi } from '@/core'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +// no_cache get时传字符串 +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + user_id: { type: 'number' }, + no_cache: { type: 'boolean' }, + }, + required: ['group_id', 'user_id'] +} as const satisfies JSONSchema; -export interface PayloadType { - group_id: number; - user_id: number; - no_cache?: boolean | string; -} +type Payload = FromSchema; -class GetGroupMemberInfo extends BaseAction { +class GetGroupMemberInfo extends BaseAction { actionName = ActionName.GetGroupMemberInfo; - - protected async _handle(payload: PayloadType) { + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { const group = await getGroup(payload.group_id.toString()); if (!group) { throw (`群(${payload.group_id})不存在`); } const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); - if (payload.no_cache == true || payload.no_cache === 'true') { + if (payload.no_cache == true /*|| payload.no_cache === 'true'*/) { groupMembers.set(group.groupCode, await NTQQGroupApi.getGroupMembers(payload.group_id.toString())); } const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString()); diff --git a/src/onebot11/action/group/GetGroupMemberList.ts b/src/onebot11/action/group/GetGroupMemberList.ts index ad2acb23..8d5d47aa 100644 --- a/src/onebot11/action/group/GetGroupMemberList.ts +++ b/src/onebot11/action/group/GetGroupMemberList.ts @@ -6,24 +6,29 @@ import { ActionName } from '../types'; import { napCatCore, NTQQGroupApi } from '@/core'; import { WebApi } from '@/core/apis/webapi'; import { logDebug } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + no_cache: { type: 'boolean' }, + }, + required: ['group_id', 'user_id'] +} as const satisfies JSONSchema; -export interface PayloadType { - group_id: number, - no_cache?: boolean | string -} +type Payload = FromSchema; - -class GetGroupMemberList extends BaseAction { +class GetGroupMemberList extends BaseAction { actionName = ActionName.GetGroupMemberList; - - protected async _handle(payload: PayloadType) { + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { const MemberMap: Map = new Map(); const webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); const group = await getGroup(payload.group_id.toString()); if (!group) { throw (`群${payload.group_id}不存在`); } - if (payload.no_cache == true || payload.no_cache === 'true') { + if (payload.no_cache == true /*|| payload.no_cache === 'true'*/) { // webGroupMembers = await WebApi.getGroupMembers(payload.group_id.toString()); const _groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString()); groupMembers.set(group.groupCode, _groupMembers); diff --git a/src/onebot11/action/group/GetGroupNotice.ts b/src/onebot11/action/group/GetGroupNotice.ts index c3c5ec33..5c548515 100644 --- a/src/onebot11/action/group/GetGroupNotice.ts +++ b/src/onebot11/action/group/GetGroupNotice.ts @@ -1,10 +1,7 @@ import { WebApi, WebApiGroupNoticeFeed, WebApiGroupNoticeRet } from '@/core/apis/webapi'; import BaseAction from '../BaseAction'; import { ActionName } from '../types'; - -interface PayloadType { - group_id: number -} +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; interface GroupNotice { sender_id: number publish_time: number @@ -17,11 +14,22 @@ interface GroupNotice { }> } } -type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed; -export class GetGroupNotice extends BaseAction { - actionName = ActionName.GoCQHTTP_GetGroupNotice; - protected async _handle(payload: PayloadType) { +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + }, + required: ['group_id'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + +type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed; +export class GetGroupNotice extends BaseAction { + actionName = ActionName.GoCQHTTP_GetGroupNotice; + PayloadSchema = SchemaData; + protected async _handle(payload: Payload) { const group = payload.group_id.toString(); const ret = await WebApi.getGrouptNotice(group); if (!ret) { diff --git a/src/onebot11/action/group/SendGroupMsg.ts b/src/onebot11/action/group/SendGroupMsg.ts index c3dfad91..464fbae1 100644 --- a/src/onebot11/action/group/SendGroupMsg.ts +++ b/src/onebot11/action/group/SendGroupMsg.ts @@ -2,7 +2,7 @@ import SendMsg from '../msg/SendMsg'; import { ActionName, BaseCheckResult } from '../types'; import { OB11PostSendMsg } from '../../types'; - +// 未检测参数 class SendGroupMsg extends SendMsg { actionName = ActionName.SendGroupMsg; diff --git a/src/onebot11/action/group/SetGroupAddRequest.ts b/src/onebot11/action/group/SetGroupAddRequest.ts index c33bd363..b76b0338 100644 --- a/src/onebot11/action/group/SetGroupAddRequest.ts +++ b/src/onebot11/action/group/SetGroupAddRequest.ts @@ -3,18 +3,23 @@ import { GroupRequestOperateTypes } from '@/core/entities'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; import { groupNotifies } from '@/core/data'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - flag: string, - // sub_type: "add" | "invite", - // type: "add" | "invite" - approve: boolean, - reason: string -} +const SchemaData = { + type: 'object', + properties: { + flag: { type: 'string' }, + approve: { type: 'boolean' }, + reason: { type: 'string' } + }, + required: ['flag', 'approve', 'reson'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupAddRequest extends BaseAction { actionName = ActionName.SetGroupAddRequest; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const flag = payload.flag.toString(); const approve = payload.approve.toString() === 'true'; diff --git a/src/onebot11/action/group/SetGroupAdmin.ts b/src/onebot11/action/group/SetGroupAdmin.ts index c88880ed..f486a66a 100644 --- a/src/onebot11/action/group/SetGroupAdmin.ts +++ b/src/onebot11/action/group/SetGroupAdmin.ts @@ -3,18 +3,26 @@ import { getGroupMember } from '@/core/data'; import { GroupMemberRole } from '@/core/entities'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - group_id: number, - user_id: number, - enable: boolean -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + user_id: { type: 'number' }, + enable: { type: 'boolean' } + }, + required: ['group_id', 'user_id', 'enable'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupAdmin extends BaseAction { actionName = ActionName.SetGroupAdmin; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const member = await getGroupMember(payload.group_id, payload.user_id); + // 已经前置验证类型 const enable = payload.enable.toString() === 'true'; if (!member) { throw `群成员${payload.user_id}不存在`; diff --git a/src/onebot11/action/group/SetGroupBan.ts b/src/onebot11/action/group/SetGroupBan.ts index 2c1fbf42..8025c6a1 100644 --- a/src/onebot11/action/group/SetGroupBan.ts +++ b/src/onebot11/action/group/SetGroupBan.ts @@ -2,16 +2,23 @@ import BaseAction from '../BaseAction'; import { getGroupMember } from '@/core/data'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - group_id: number, - user_id: number, - duration: number -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + user_id: { type: 'number' }, + duration: { type: 'number' } + }, + required: ['group_id', 'user_id', 'duration'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupBan extends BaseAction { actionName = ActionName.SetGroupBan; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const member = await getGroupMember(payload.group_id, payload.user_id); if (!member) { diff --git a/src/onebot11/action/group/SetGroupCard.ts b/src/onebot11/action/group/SetGroupCard.ts index 548af09a..b7b1eab9 100644 --- a/src/onebot11/action/group/SetGroupCard.ts +++ b/src/onebot11/action/group/SetGroupCard.ts @@ -2,16 +2,23 @@ import BaseAction from '../BaseAction'; import { getGroupMember } from '@/core/data'; import { ActionName } from '../types'; import { NTQQGroupApi } from '@/core/apis/group'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; -interface Payload { - group_id: number, - user_id: number, - card: string -} +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + user_id: { type: 'number' }, + card: { type: 'string' } + }, + required: ['group_id', 'user_id', 'card'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; export default class SetGroupCard extends BaseAction { actionName = ActionName.SetGroupCard; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const member = await getGroupMember(payload.group_id, payload.user_id); if (!member) {