From 988d9995c51e38343a7cd6c6e476611234c58f69 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 11 Mar 2023 00:46:20 +0600 Subject: [PATCH] add sticker format to sticker object --- .../dev/inmo/tgbotapi/types/files/Sticker.kt | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt index 248e1a2e98..c95fc364d4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt @@ -35,6 +35,7 @@ data class StickerSurrogate( sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile { val emoji: String? val stickerSetName: StickerSetName? + val stickerFormat: StickerFormat val isAnimated get() = false @@ -165,6 +166,11 @@ object StickerSerializer : KSerializer { surrogate.emoji, surrogate.set_name, surrogate.file_size, + when { + surrogate.is_animated == true -> StickerFormat.Animated + surrogate.is_video == true -> StickerFormat.Video + else -> StickerFormat.Static + }, json ) } @@ -180,11 +186,17 @@ object StickerSerializer : KSerializer { sealed interface VideoSticker : Sticker { override val isVideo: Boolean get() = true + + override val stickerFormat: StickerFormat + get() = StickerFormat.Video } @Serializable sealed interface AnimatedSticker : Sticker { override val isAnimated: Boolean get() = true + + override val stickerFormat: StickerFormat + get() = StickerFormat.Animated } @Serializable @@ -209,10 +221,14 @@ data class RegularSimpleSticker( @SerialName(stickerSetNameField) override val stickerSetName: StickerSetName? = null, @SerialName(premiumAnimationField) - override val premiumAnimationFile: File?, + override val premiumAnimationFile: File? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : RegularSticker +) : RegularSticker { + @SerialName(stickerFormatField) + @EncodeDefault + override val stickerFormat: StickerFormat = StickerFormat.Static +} @Serializable data class RegularAnimatedSticker( @@ -231,7 +247,7 @@ data class RegularAnimatedSticker( @SerialName(stickerSetNameField) override val stickerSetName: StickerSetName? = null, @SerialName(premiumAnimationField) - override val premiumAnimationFile: File?, + override val premiumAnimationFile: File? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, ) : RegularSticker, AnimatedSticker @@ -252,7 +268,7 @@ data class RegularVideoSticker( @SerialName(stickerSetNameField) override val stickerSetName: StickerSetName? = null, @SerialName(premiumAnimationField) - override val premiumAnimationFile: File?, + override val premiumAnimationFile: File? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, ) : RegularSticker, VideoSticker @@ -282,7 +298,11 @@ data class MaskSimpleSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, -) : MaskSticker +) : MaskSticker { + @SerialName(stickerFormatField) + @EncodeDefault + override val stickerFormat: StickerFormat = StickerFormat.Static +} @Serializable data class MaskAnimatedSticker( @SerialName(fileIdField) @@ -354,7 +374,11 @@ data class CustomEmojiSimpleSticker( override val fileSize: Long? = null, @SerialName(needsRepaintingField) override val needsRepainting: Boolean = false -) : CustomEmojiSticker +) : CustomEmojiSticker { + @SerialName(stickerFormatField) + @EncodeDefault + override val stickerFormat: StickerFormat = StickerFormat.Static +} @Serializable data class CustomEmojiAnimatedSticker( @SerialName(fileIdField) @@ -420,5 +444,7 @@ data class UnknownSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(stickerFormatField) + override val stickerFormat: StickerFormat = StickerFormat.Static, val raw: JsonElement ) : Sticker