refactor: MsgId

This commit is contained in:
手瓜一十雪
2024-07-22 11:15:01 +08:00
parent 2ed01773b7
commit 5f7874af8f
18 changed files with 90 additions and 104 deletions

View File

@@ -4,6 +4,8 @@ import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { dbUtil } from '@/common/utils/db';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/utils/MessageUnique';
import { NTQQMsgApi } from '@/core';
export type ReturnDataType = OB11Message
@@ -11,7 +13,7 @@ export type ReturnDataType = OB11Message
const SchemaData = {
type: 'object',
properties: {
message_id: { type: ['number','string'] },
message_id: { type: ['number', 'string'] },
},
required: ['message_id']
} as const satisfies JSONSchema;
@@ -26,14 +28,15 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
if (!payload.message_id) {
throw Error('参数message_id不能为空');
}
let msg = await dbUtil.getMsgByShortId(parseInt(payload.message_id.toString()));
if (!msg) {
msg = await dbUtil.getMsgByLongId(payload.message_id.toString());
}
if (!msg) {
let MsgShortId = await MessageUnique.getShortIdByMsgId(payload.message_id.toString());
let msgIdWithPeer = await MessageUnique.getMsgIdAndPeerByShortId(MsgShortId || parseInt(payload.message_id.toString()));
if (!msgIdWithPeer) {
throw ('消息不存在');
}
return await OB11Constructor.message(msg);
let msg = await NTQQMsgApi.getMsgsByMsgId(
{ guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType },
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
return await OB11Constructor.message(msg.msgList[0]);
}
}