feat: action check data

This commit is contained in:
手瓜一十雪
2024-05-18 11:48:38 +08:00
parent f4d584765a
commit d4e5201913
8 changed files with 158 additions and 46 deletions

View File

@@ -3,12 +3,19 @@ import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types';
import { NTQQMsgApi } from '@/core/apis';
import { dbUtil } from '@/core/utils/db';
import { OB11Constructor } from '../../constructor';
import { ActionName } from '../types';
import { ActionName, BaseCheckResult } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import Ajv from 'ajv';
interface Payload {
message_id: string; // long msg id
id?: string; // short msg id
}
const SchemaData = {
type: 'object',
properties: {
message_id: { type: 'string' },
id: { type: 'string' }
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
interface Response {
messages: (OB11Message & { content: OB11MessageData })[];
@@ -16,7 +23,7 @@ interface Response {
export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
actionName = ActionName.GoCQHTTP_GetForwardMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
const msgId = payload.message_id || payload.id;
if (!msgId) {
@@ -25,7 +32,7 @@ export class GoCQHTTGetForwardMsgAction extends BaseAction<Payload, any> {
let rootMsg = await dbUtil.getMsgByLongId(msgId);
if (!rootMsg) {
rootMsg = await dbUtil.getMsgByShortId(parseInt(msgId));
if (!rootMsg){
if (!rootMsg) {
throw Error('msg not found');
}
}