mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Http api fix MessageSource lost and ignore Unknown type message
This commit is contained in:
parent
63c3a64ceb
commit
bebcf1aacb
@ -64,7 +64,7 @@ data class XmlDTO(val xml: String) : MessageDTO()
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("Unknown")
|
@SerialName("Unknown")
|
||||||
data class UnknownMessageDTO(val text: String) : MessageDTO()
|
object UnknownMessageDTO : MessageDTO()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Abstract Class
|
* Abstract Class
|
||||||
@ -88,9 +88,12 @@ fun MessagePacket<*, *>.toDTO() = when (this) {
|
|||||||
is GroupMessage -> GroupMessagePacketDTO(MemberDTO(sender))
|
is GroupMessage -> GroupMessagePacketDTO(MemberDTO(sender))
|
||||||
else -> IgnoreEventDTO
|
else -> IgnoreEventDTO
|
||||||
}.apply {
|
}.apply {
|
||||||
if (this is MessagePacketDTO) {
|
if (this is MessagePacketDTO) { messageChain = message.toDTOChain() }
|
||||||
messageChain = mutableListOf<MessageDTO>().also { ls -> message.foreachContent { ls.add(it.toDTO()) } }
|
// else: `this` is bot event
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun MessageChain.toDTOChain() = mutableListOf(this[MessageSource].toDTO()).apply {
|
||||||
|
foreachContent { content -> content.toDTO().takeUnless { it == UnknownMessageDTO }?.let(::add) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun MessageChainDTO.toMessageChain(contact: Contact) =
|
fun MessageChainDTO.toMessageChain(contact: Contact) =
|
||||||
@ -105,7 +108,7 @@ fun Message.toDTO() = when (this) {
|
|||||||
is PlainText -> PlainDTO(stringValue)
|
is PlainText -> PlainDTO(stringValue)
|
||||||
is Image -> ImageDTO(imageId)
|
is Image -> ImageDTO(imageId)
|
||||||
is XMLMessage -> XmlDTO(stringValue)
|
is XMLMessage -> XmlDTO(stringValue)
|
||||||
else -> UnknownMessageDTO("未知消息类型")
|
else -> UnknownMessageDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseExperimental(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class)
|
@UseExperimental(ExperimentalUnsignedTypes::class, MiraiInternalAPI::class)
|
||||||
|
Loading…
Reference in New Issue
Block a user