http api fix Polymorphic

This commit is contained in:
ryoii 2020-02-20 19:01:32 +08:00
parent 3a45832270
commit f7ab3b2608
3 changed files with 12 additions and 21 deletions

View File

@ -9,7 +9,7 @@ import net.mamoe.mirai.message.MessagePacket
import net.mamoe.mirai.utils.MiraiExperimentalAPI
@Serializable
open class BotEventDTO : EventDTO()
sealed class BotEventDTO : EventDTO()
@UseExperimental(MiraiExperimentalAPI::class)
fun BotEvent.toDTO() = when(this) {

View File

@ -17,6 +17,6 @@ abstract class VerifyDTO : DTO {
}
@Serializable
open class EventDTO : DTO
abstract class EventDTO : DTO
object IgnoreEventDTO : EventDTO()

View File

@ -46,19 +46,10 @@ object MiraiJson {
val json = Json(context = SerializersModule {
polymorphic(EventDTO.serializer()) {
BotEventDTO::class with BotEventDTO.serializer()
MessagePacketDTO::class with MessagePacketDTO.serializer()
}
polymorphic(MessagePacketDTO.serializer()) {
GroupMessagePacketDTO::class with GroupMessagePacketDTO.serializer()
FriendMessagePacketDTO::class with FriendMessagePacketDTO.serializer()
UnKnownMessagePacketDTO::class with UnKnownMessagePacketDTO.serializer()
}
// Bot Event Polymorphic
polymorphic(BotEventDTO.serializer()) {
BotOnlineEventDTO::class with BotOnlineEventDTO.serializer()
BotOfflineEventActiveDTO::class with BotOfflineEventActiveDTO.serializer()
BotOfflineEventForceDTO::class with BotOfflineEventForceDTO.serializer()
@ -85,15 +76,15 @@ object MiraiJson {
}
// Message Polymorphic
polymorphic(MessageDTO.serializer()) {
MessageSourceDTO::class with MessageSourceDTO.serializer()
AtDTO::class with AtDTO.serializer()
AtAllDTO::class with AtAllDTO.serializer()
FaceDTO::class with FaceDTO.serializer()
PlainDTO::class with PlainDTO.serializer()
ImageDTO::class with ImageDTO.serializer()
XmlDTO::class with XmlDTO.serializer()
UnknownMessageDTO::class with UnknownMessageDTO.serializer()
}
// polymorphic(MessageDTO.serializer()) {
// MessageSourceDTO::class with MessageSourceDTO.serializer()
// AtDTO::class with AtDTO.serializer()
// AtAllDTO::class with AtAllDTO.serializer()
// FaceDTO::class with FaceDTO.serializer()
// PlainDTO::class with PlainDTO.serializer()
// ImageDTO::class with ImageDTO.serializer()
// XmlDTO::class with XmlDTO.serializer()
// UnknownMessageDTO::class with UnknownMessageDTO.serializer()
// }
})
}