mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-03-03 17:32:23 +00:00
add rarity support
This commit is contained in:
@@ -546,6 +546,7 @@ const val giftField = "gift"
|
||||
const val giftUpgradeSentField = "gift_upgrade_sent"
|
||||
const val giftsField = "gifts"
|
||||
const val rarityPerMilleField = "rarity_per_mille"
|
||||
const val rarityField = "rarity"
|
||||
const val acceptedGiftTypesField = "accepted_gift_types"
|
||||
const val ownedGiftIdField = "owned_gift_id"
|
||||
const val convertStarCountField = "convert_star_count"
|
||||
@@ -754,7 +755,6 @@ const val paidMediaField = "paid_media"
|
||||
const val publisherChatField = "publisher_chat"
|
||||
const val personalTotalCountField = "personal_total_count"
|
||||
const val personalRemainingCountField = "personal_remaining_count"
|
||||
const val isPremiumField2 = "is_premium"
|
||||
const val hasColorsField = "has_colors"
|
||||
const val uniqueGiftVariantCountField = "unique_gift_variant_count"
|
||||
const val uniqueGiftNumberField = "unique_gift_number"
|
||||
|
||||
@@ -49,7 +49,7 @@ sealed interface Gift {
|
||||
override val personalTotalCount: Int? = null,
|
||||
@SerialName(personalRemainingCountField)
|
||||
override val personalRemainingCount: Int? = null,
|
||||
@SerialName(isPremiumField2)
|
||||
@SerialName(isPremiumField)
|
||||
override val isPremium: Boolean = false,
|
||||
@SerialName(hasColorsField)
|
||||
override val hasColors: Boolean = false,
|
||||
@@ -84,7 +84,7 @@ sealed interface Gift {
|
||||
override val personalTotalCount: Int? = null,
|
||||
@SerialName(personalRemainingCountField)
|
||||
override val personalRemainingCount: Int? = null,
|
||||
@SerialName(isPremiumField2)
|
||||
@SerialName(isPremiumField)
|
||||
override val isPremium: Boolean = false,
|
||||
@SerialName(hasColorsField)
|
||||
override val hasColors: Boolean = false,
|
||||
@@ -193,7 +193,7 @@ sealed interface Gift {
|
||||
override val publisherChat: PreviewChat? = null,
|
||||
@SerialName(isFromBlockchainField)
|
||||
val isFromBlockchain: Boolean = false,
|
||||
@SerialName(isPremiumField2)
|
||||
@SerialName(isPremiumField)
|
||||
val isPremium: Boolean = false,
|
||||
@SerialName(colorsField)
|
||||
val colors: UniqueGiftColors? = null
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package dev.inmo.tgbotapi.types.gifts
|
||||
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(Rarity.Companion::class)
|
||||
sealed interface Rarity {
|
||||
val name: String
|
||||
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(Rarity.Companion::class)
|
||||
data object Uncommon : Rarity { override val name: String = "uncommon" }
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(Rarity.Companion::class)
|
||||
data object Rare : Rarity { override val name: String = "rare" }
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(Rarity.Companion::class)
|
||||
data object Epic : Rarity { override val name: String = "epic" }
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(Rarity.Companion::class)
|
||||
data object Legendary : Rarity { override val name: String = "legendary" }
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(Rarity.Companion::class)
|
||||
data class Custom(override val name: String) : Rarity
|
||||
|
||||
companion object : KSerializer<Rarity> {
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
|
||||
fun fromString(value: String): Rarity = when (value) {
|
||||
Uncommon.name -> Uncommon
|
||||
Rare.name -> Rare
|
||||
Epic.name -> Epic
|
||||
Legendary.name -> Legendary
|
||||
else -> Custom(value)
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): Rarity {
|
||||
val value = decoder.decodeString()
|
||||
return fromString(value)
|
||||
}
|
||||
|
||||
override fun serialize(
|
||||
encoder: Encoder,
|
||||
value: Rarity
|
||||
) {
|
||||
encoder.encodeString(value.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.gifts.unique
|
||||
|
||||
import dev.inmo.tgbotapi.types.files.Sticker
|
||||
import dev.inmo.tgbotapi.types.gifts.Rarity
|
||||
import dev.inmo.tgbotapi.types.nameField
|
||||
import dev.inmo.tgbotapi.types.rarityField
|
||||
import dev.inmo.tgbotapi.types.rarityPerMilleField
|
||||
import dev.inmo.tgbotapi.types.stickerField
|
||||
import kotlinx.serialization.SerialName
|
||||
@@ -15,5 +17,7 @@ data class UniqueGiftModel(
|
||||
@SerialName(stickerField)
|
||||
val sticker: Sticker,
|
||||
@SerialName(rarityPerMilleField)
|
||||
val rarityPerMille: Int
|
||||
val rarityPerMille: Int,
|
||||
@SerialName(rarityField)
|
||||
val rarity: Rarity
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user