mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import BaseAction from '../BaseAction'
|
|
import { OB11Message } from '../../types'
|
|
import { OB11Constructor } from '../../constructor'
|
|
import { ActionName } from '../types'
|
|
import { MessageUnique } from '@/common/utils/MessageUnique'
|
|
|
|
export interface PayloadType {
|
|
message_id: number | string
|
|
}
|
|
|
|
export type ReturnDataType = OB11Message
|
|
|
|
class GetMsg extends BaseAction<PayloadType, OB11Message> {
|
|
actionName = ActionName.GetMsg
|
|
|
|
protected async _handle(payload: PayloadType) {
|
|
if (!payload.message_id) {
|
|
throw '参数message_id不能为空'
|
|
}
|
|
const msgShortId = MessageUnique.getShortIdByMsgId(payload.message_id.toString())
|
|
const msgIdWithPeer = await MessageUnique.getMsgIdAndPeerByShortId(msgShortId || +payload.message_id)
|
|
if (!msgIdWithPeer) {
|
|
throw ('消息不存在')
|
|
}
|
|
const peer = {
|
|
guildId: '',
|
|
peerUid: msgIdWithPeer.Peer.peerUid,
|
|
chatType: msgIdWithPeer.Peer.chatType
|
|
}
|
|
const msg = this.adapter.getMsgCache(msgIdWithPeer.MsgId) ?? (await this.ctx.ntMsgApi.getMsgsByMsgId(peer, [msgIdWithPeer.MsgId])).msgList[0]
|
|
const retMsg = await OB11Constructor.message(this.ctx, msg)
|
|
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgId)!
|
|
retMsg.message_seq = retMsg.message_id
|
|
retMsg.real_id = retMsg.message_id
|
|
return retMsg
|
|
}
|
|
}
|
|
|
|
export default GetMsg
|