mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
RawGame added
This commit is contained in:
parent
44751d94b3
commit
704457715d
@ -1,6 +1,6 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.18.0
|
||||
## 0.18.0 Raws cleaning
|
||||
|
||||
* Made internal and not available outside of library:
|
||||
* `RawMessage`
|
||||
@ -17,8 +17,9 @@
|
||||
* `TelegramBotAPIMessageDeserializeOnlySerializer` was created. It **MUST NOT** be used to serialize messages
|
||||
* Update of description
|
||||
* Make `Game` object a little bit more standartizated
|
||||
* `Game` now is not serializable and have no additional trash, related to serialization
|
||||
|
||||
## 0.17.0
|
||||
## 0.17.0 July 29, 2019 API Update
|
||||
|
||||
Libraries updates:
|
||||
|
||||
|
@ -9,23 +9,14 @@ import kotlinx.serialization.internal.StringDescriptor
|
||||
import kotlinx.serialization.json.*
|
||||
import java.lang.UnsupportedOperationException
|
||||
|
||||
@Serializable(GameSerializer::class)
|
||||
data class Game(
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(descriptionField)
|
||||
val description: String,
|
||||
@Serializable(PhotoSerializer::class)
|
||||
@SerialName(photoField)
|
||||
val photo: Photo,
|
||||
@SerialName(textField)
|
||||
override val caption: String? = null,
|
||||
@SerialName(textEntitiesField)
|
||||
override val captionEntities: List<MessageEntity> = emptyList(),
|
||||
@SerialName(animationField)
|
||||
val animation: AnimationFile? = null
|
||||
) : Titled, CaptionedInput {
|
||||
|
||||
@Deprecated(
|
||||
"Missinterfaced field",
|
||||
ReplaceWith("caption")
|
||||
@ -42,43 +33,3 @@ data class Game(
|
||||
val textEntities: List<MessageEntity>?
|
||||
get() = captionEntities
|
||||
}
|
||||
|
||||
internal object GameSerializer : KSerializer<Game> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName("GameSerializer")
|
||||
|
||||
override fun deserialize(decoder: Decoder): Game {
|
||||
val json = JsonObjectSerializer.deserialize(decoder)
|
||||
|
||||
val text = json.getPrimitiveOrNull(textField) ?.content
|
||||
|
||||
return Game(
|
||||
json.getPrimitive(titleField).content,
|
||||
json.getPrimitive(descriptionField).content,
|
||||
Json.nonstrict.fromJson(
|
||||
PhotoSerializer,
|
||||
json.getObject(photoField)
|
||||
),
|
||||
text,
|
||||
text ?.let {
|
||||
Json.nonstrict.fromJson(
|
||||
RawMessageEntitiesSerializer,
|
||||
json.getArray(textEntitiesField)
|
||||
).map {
|
||||
it.asMessageEntity(text)
|
||||
}
|
||||
} ?: emptyList(),
|
||||
json.getObjectOrNull(
|
||||
animationField
|
||||
) ?.let { animatedFileJson ->
|
||||
Json.nonstrict.fromJson(
|
||||
AnimationFile.serializer(),
|
||||
animatedFileJson
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: Game) = throw UnsupportedOperationException(
|
||||
"Objects of class Game can't be serialized for now"
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.games
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
|
||||
@Serializable
|
||||
internal data class RawGame(
|
||||
@SerialName(titleField)
|
||||
private val title: String,
|
||||
@SerialName(descriptionField)
|
||||
private val description: String,
|
||||
@Serializable(PhotoSerializer::class)
|
||||
@SerialName(photoField)
|
||||
private val photo: Photo,
|
||||
@SerialName(textField)
|
||||
private val caption: String? = null,
|
||||
@SerialName(textEntitiesField)
|
||||
private val captionEntities: RawMessageEntities = emptyList(),
|
||||
@SerialName(animationField)
|
||||
private val animation: AnimationFile? = null
|
||||
) {
|
||||
@Transient
|
||||
val asGame = Game(
|
||||
title,
|
||||
description,
|
||||
photo,
|
||||
caption,
|
||||
caption ?.let { _ -> captionEntities.map { it.asMessageEntity(caption) } } ?: emptyList(),
|
||||
animation
|
||||
)
|
||||
}
|
@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMa
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.RawGame
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
@ -44,15 +45,13 @@ internal data class RawMessage(
|
||||
private val media_group_id: MediaGroupIdentifier? = null,
|
||||
private val author_signature: AuthorSignature? = null,
|
||||
private val text: String? = null,
|
||||
@Serializable(RawMessageEntitiesSerializer::class)
|
||||
private val entities: RawMessageEntities? = null,
|
||||
private val caption: String? = null,
|
||||
@Serializable(RawMessageEntitiesSerializer::class)
|
||||
private val caption_entities: RawMessageEntities? = null,
|
||||
private val audio: AudioFile? = null,
|
||||
private val document: DocumentFile? = null,
|
||||
private val animation: AnimationFile? = null,
|
||||
private val game: Game? = null,
|
||||
private val game: RawGame? = null,
|
||||
@Serializable(PhotoSerializer::class)
|
||||
private val photo: Photo? = null,
|
||||
private val sticker: Sticker? = null,
|
||||
@ -128,7 +127,7 @@ internal data class RawMessage(
|
||||
adaptedCaptionEntities
|
||||
)
|
||||
sticker != null -> StickerContent(sticker)
|
||||
game != null -> GameContent(game)
|
||||
game != null -> GameContent(game.asGame)
|
||||
video_note != null -> VideoNoteContent(video_note)
|
||||
contact != null -> ContactContent(contact)
|
||||
location != null -> LocationContent(location)
|
||||
|
Loading…
Reference in New Issue
Block a user