diff --git a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts index 2ef3151c..e279a5ba 100644 --- a/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetFriendMsgHistory.ts @@ -7,21 +7,27 @@ import { dbUtil } from '@/core/utils/db'; import { NTQQMsgApi } from '@/core/apis/msg'; import { OB11Constructor } from '../../constructor'; import { logDebug } from '@/common/utils/log'; - - -interface Payload { - user_id: number - message_seq: number, - count: number -} +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; interface Response { - messages: OB11Message[]; + messages: OB11Message[]; } +const SchemaData = { + type: 'object', + properties: { + user_id: { type: 'number' }, + message_seq: { type: 'number' }, + count: { type: 'number' } + }, + required: ['user_id', 'message_seq', 'count'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + export default class GetFriendMsgHistory extends BaseAction { actionName = ActionName.GetFriendMsgHistory; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const uid = getUidByUin(payload.user_id.toString()); if (!uid) { diff --git a/src/onebot11/action/go-cqhttp/GetGroupHonorInfo.ts b/src/onebot11/action/go-cqhttp/GetGroupHonorInfo.ts index 95fceba4..3a896f9d 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupHonorInfo.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupHonorInfo.ts @@ -1,21 +1,23 @@ -import { OB11User } from '../../types'; -import { OB11Constructor } from '../../constructor'; -import { friends } from '@/core/data'; + import BaseAction from '../BaseAction'; import { ActionName } from '../types'; -import { NTQQUserApi, WebApi, WebHonorType } from '@/core/apis'; -interface Payload { - group_id: number, - type?: WebHonorType -} +import { WebApi, WebHonorType } from '@/core/apis'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFROMER, WebHonorType.STORONGE_NEWBI, WebHonorType.TALKACTIVE] } + }, + required: ['group_id'] +} as const satisfies JSONSchema; +// enum是不是有点抽象 +type Payload = FromSchema; + export class GetGroupHonorInfo extends BaseAction> { actionName = ActionName.GetGroupHonorInfo; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload) { - // console.log(await NTQQUserApi.getRobotUinRange()); - if (!payload.group_id) { - throw '缺少参数group_id'; - } if (!payload.type) { payload.type = WebHonorType.ALL; } diff --git a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts index 65bd549c..e371d0e5 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupMsgHistory.ts @@ -7,21 +7,26 @@ import { dbUtil } from '@/core/utils/db'; import { NTQQMsgApi } from '@/core/apis/msg'; import { OB11Constructor } from '../../constructor'; import { logDebug } from '@/common/utils/log'; - - -interface Payload { - group_id: number - message_seq: number, - count: number -} - +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; interface Response { messages: OB11Message[]; } +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + message_seq: { type: 'number' }, + count: { type: 'number' } + }, + required: ['group_id', 'message_seq', 'count'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; + export default class GoCQHTTPGetGroupMsgHistory extends BaseAction { actionName = ActionName.GoCQHTTP_GetGroupMsgHistory; - + PayloadSchema = SchemaData; protected async _handle(payload: Payload): Promise { const group = await getGroup(payload.group_id.toString()); if (!group) { diff --git a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts index 5da2da3f..0819234a 100644 --- a/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts +++ b/src/onebot11/action/go-cqhttp/GetStrangerInfo.ts @@ -5,12 +5,22 @@ import { OB11Constructor } from '../../constructor'; import { ActionName } from '../types'; import { NTQQUserApi } from '@/core/apis/user'; import { log, logDebug } from '@/common/utils/log'; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + user_id: { type: 'number' }, + }, + required: ['user_id'] +} as const satisfies JSONSchema; -export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: number }, OB11User> { +type Payload = FromSchema; + +export default class GoCQHTTPGetStrangerInfo extends BaseAction { actionName = ActionName.GoCQHTTP_GetStrangerInfo; - protected async _handle(payload: { user_id: number }): Promise { + protected async _handle(payload: Payload): Promise { const user_id = payload.user_id.toString(); logDebug('uidMaps', uid2UinMap); const uid = getUidByUin(user_id); diff --git a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts index f866816e..fab6d218 100644 --- a/src/onebot11/action/go-cqhttp/SendForwardMsg.ts +++ b/src/onebot11/action/go-cqhttp/SendForwardMsg.ts @@ -1,7 +1,7 @@ import SendMsg, { normalize } from '../msg/SendMsg'; import { OB11PostSendMsg } from '../../types'; import { ActionName } from '../types'; - +// 未验证 export class GoCQHTTPSendForwardMsg extends SendMsg { actionName = ActionName.GoCQHTTP_SendForwardMsg; diff --git a/src/onebot11/action/go-cqhttp/SendGroupNotice.ts b/src/onebot11/action/go-cqhttp/SendGroupNotice.ts index 47ff7c84..f9d10ee0 100644 --- a/src/onebot11/action/go-cqhttp/SendGroupNotice.ts +++ b/src/onebot11/action/go-cqhttp/SendGroupNotice.ts @@ -3,14 +3,21 @@ import BaseAction from '../BaseAction'; import { ActionName } from '../types'; import { NTQQGroupApi, WebApi } from '@/core/apis'; import { unlink } from 'node:fs'; -interface Payload { - group_id: string; - content: string; - image?: string; - pinned?: number; - confirmRequired?: number; +import { FromSchema, JSONSchema } from 'json-schema-to-ts'; +const SchemaData = { + type: 'object', + properties: { + group_id: { type: 'number' }, + content: { type: 'string' }, + image: { type: 'string' }, + pinned: { type: 'number' }, + confirmRequired: { type: 'number' } + }, + required: ['group_id', 'content'] +} as const satisfies JSONSchema; + +type Payload = FromSchema; -} export class SendGroupNotice extends BaseAction { actionName = ActionName.GoCQHTTP_SendGroupNotice; protected async _handle(payload: Payload) { @@ -29,7 +36,7 @@ export class SendGroupNotice extends BaseAction { throw `群公告${payload.image}设置失败,获取资源失败`; } await checkFileReceived(Image_path, 5000); // 文件不存在QQ会崩溃,需要提前判断 - let ImageUploadResult = await NTQQGroupApi.uploadGroupBulletinPic(payload.group_id, Image_path); + let ImageUploadResult = await NTQQGroupApi.uploadGroupBulletinPic(payload.group_id.toString(), Image_path); if (ImageUploadResult.errCode != 0) { throw `群公告${payload.image}设置失败,图片上传失败`; } @@ -46,7 +53,7 @@ export class SendGroupNotice extends BaseAction { if (!payload.confirmRequired) { Notice_confirmRequired = 0; } - let PublishGroupBulletinResult = await NTQQGroupApi.publishGroupBulletin(payload.group_id, payload.content, UploadImage, Notice_Pinned, Notice_confirmRequired); + let PublishGroupBulletinResult = await NTQQGroupApi.publishGroupBulletin(payload.group_id.toString(), payload.content, UploadImage, Notice_Pinned, Notice_confirmRequired); if (PublishGroupBulletinResult.result! = 0) { throw `设置群公告失败,错误信息:${PublishGroupBulletinResult.errMsg}`;