feat: check action data 2

This commit is contained in:
手瓜一十雪 2024-05-18 12:23:15 +08:00
parent d4e5201913
commit 62eee5f05c
6 changed files with 73 additions and 43 deletions

View File

@ -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<typeof SchemaData>;
export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GetFriendMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
const uid = getUidByUin(payload.user_id.toString());
if (!uid) {

View File

@ -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<typeof SchemaData>;
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
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;
}

View File

@ -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<typeof SchemaData>;
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
const group = await getGroup(payload.group_id.toString());
if (!group) {

View File

@ -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<typeof SchemaData>;
export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11User> {
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
protected async _handle(payload: { user_id: number }): Promise<OB11User> {
protected async _handle(payload: Payload): Promise<OB11User> {
const user_id = payload.user_id.toString();
logDebug('uidMaps', uid2UinMap);
const uid = getUidByUin(user_id);

View File

@ -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;

View File

@ -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<typeof SchemaData>;
}
export class SendGroupNotice extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SendGroupNotice;
protected async _handle(payload: Payload) {
@ -29,7 +36,7 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
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<Payload, null> {
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}`;