mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
start support of prize_star_count
This commit is contained in:
parent
1980f8a9ca
commit
6809b9d2ef
@ -288,6 +288,7 @@ const val requestUsernameField = "request_username"
|
|||||||
const val requestPhotoField = "request_photo"
|
const val requestPhotoField = "request_photo"
|
||||||
const val requestNameField = "request_name"
|
const val requestNameField = "request_name"
|
||||||
const val maxQuantityField = "max_quantity"
|
const val maxQuantityField = "max_quantity"
|
||||||
|
const val prizeStarCountField = "prize_star_count"
|
||||||
|
|
||||||
const val userIsBotField = "user_is_bot"
|
const val userIsBotField = "user_is_bot"
|
||||||
const val userIsPremiumField = "user_is_premium"
|
const val userIsPremiumField = "user_is_premium"
|
||||||
|
@ -57,13 +57,16 @@ sealed interface ChatBoostSource {
|
|||||||
val unclaimed: Boolean
|
val unclaimed: Boolean
|
||||||
val claimed: Boolean
|
val claimed: Boolean
|
||||||
get() = !unclaimed
|
get() = !unclaimed
|
||||||
|
val prizeStarCount: Int?
|
||||||
|
|
||||||
@Serializable(ChatBoostSource.Companion::class)
|
@Serializable(ChatBoostSource.Companion::class)
|
||||||
data class Claimed(
|
data class Claimed(
|
||||||
@SerialName(giveawayMessageIdField)
|
@SerialName(giveawayMessageIdField)
|
||||||
override val messageId: MessageId,
|
override val messageId: MessageId,
|
||||||
@SerialName(userField)
|
@SerialName(userField)
|
||||||
override val user: PreviewUser
|
override val user: PreviewUser,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int?
|
||||||
) : Giveaway, ByUser {
|
) : Giveaway, ByUser {
|
||||||
@Required
|
@Required
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -78,7 +81,9 @@ sealed interface ChatBoostSource {
|
|||||||
@Serializable(ChatBoostSource.Companion::class)
|
@Serializable(ChatBoostSource.Companion::class)
|
||||||
data class Unclaimed(
|
data class Unclaimed(
|
||||||
@SerialName(giveawayMessageIdField)
|
@SerialName(giveawayMessageIdField)
|
||||||
override val messageId: MessageId
|
override val messageId: MessageId,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int?
|
||||||
) : Giveaway {
|
) : Giveaway {
|
||||||
@Required
|
@Required
|
||||||
@EncodeDefault
|
@EncodeDefault
|
||||||
@ -115,7 +120,9 @@ sealed interface ChatBoostSource {
|
|||||||
@SerialName(giveawayMessageIdField)
|
@SerialName(giveawayMessageIdField)
|
||||||
val messageId: MessageId? = null,
|
val messageId: MessageId? = null,
|
||||||
@SerialName(isUnclaimedField)
|
@SerialName(isUnclaimedField)
|
||||||
val unclaimed: Boolean? = null
|
val unclaimed: Boolean? = null,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
val prizeStarCount: Int?
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object : KSerializer<ChatBoostSource> {
|
companion object : KSerializer<ChatBoostSource> {
|
||||||
@ -143,10 +150,12 @@ sealed interface ChatBoostSource {
|
|||||||
when {
|
when {
|
||||||
surrogate.user != null && surrogate.unclaimed == false -> Giveaway.Claimed(
|
surrogate.user != null && surrogate.unclaimed == false -> Giveaway.Claimed(
|
||||||
surrogate.messageId,
|
surrogate.messageId,
|
||||||
surrogate.user
|
surrogate.user,
|
||||||
|
surrogate.prizeStarCount
|
||||||
)
|
)
|
||||||
surrogate.unclaimed == true -> Giveaway.Unclaimed(
|
surrogate.unclaimed == true -> Giveaway.Unclaimed(
|
||||||
surrogate.messageId
|
surrogate.messageId,
|
||||||
|
surrogate.prizeStarCount
|
||||||
)
|
)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
@ -166,6 +175,7 @@ sealed interface ChatBoostSource {
|
|||||||
value.user,
|
value.user,
|
||||||
(value as? Giveaway) ?.messageId,
|
(value as? Giveaway) ?.messageId,
|
||||||
(value as? Giveaway) ?.unclaimed,
|
(value as? Giveaway) ?.unclaimed,
|
||||||
|
(value as? Giveaway) ?.prizeStarCount
|
||||||
)
|
)
|
||||||
|
|
||||||
Surrogate.serializer().serialize(encoder, surrogate)
|
Surrogate.serializer().serialize(encoder, surrogate)
|
||||||
|
@ -23,5 +23,7 @@ data class Giveaway(
|
|||||||
@SerialName(countryCodesField)
|
@SerialName(countryCodesField)
|
||||||
val countries: List<IetfLang>? = null,
|
val countries: List<IetfLang>? = null,
|
||||||
@SerialName(premiumSubscriptionMonthCountField)
|
@SerialName(premiumSubscriptionMonthCountField)
|
||||||
override val premiumMonths: Int? = null
|
override val premiumMonths: Int? = null,
|
||||||
) : GiveawayInfo, ReplyInfo.External.ContentVariant
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int? = null
|
||||||
|
) : GiveawayInfo.OptionallyStars, GiveawayInfo.OptionallyPremium, ReplyInfo.External.ContentVariant
|
@ -2,7 +2,54 @@ package dev.inmo.tgbotapi.types.giveaway
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent
|
||||||
|
import dev.inmo.tgbotapi.types.prizeStarCountField
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
@Serializable
|
@Serializable(GiveawayCreated.Serializer::class)
|
||||||
object GiveawayCreated : ChatEvent, PublicChatEvent
|
sealed interface GiveawayCreated : ChatEvent, PublicChatEvent {
|
||||||
|
val prizeStarCount: Int?
|
||||||
|
@Serializable
|
||||||
|
data class Stars(
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int
|
||||||
|
) : GiveawayCreated
|
||||||
|
|
||||||
|
object Serializer : KSerializer<GiveawayCreated> {
|
||||||
|
@Serializable
|
||||||
|
private data class Surrogate(
|
||||||
|
val prizeStarCount: Int?
|
||||||
|
)
|
||||||
|
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = Surrogate.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): GiveawayCreated {
|
||||||
|
val surrogate = Surrogate.serializer().deserialize(decoder)
|
||||||
|
return when {
|
||||||
|
surrogate.prizeStarCount == null -> Common
|
||||||
|
else -> Stars(surrogate.prizeStarCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: GiveawayCreated) {
|
||||||
|
Surrogate.serializer().serialize(
|
||||||
|
encoder,
|
||||||
|
Surrogate(
|
||||||
|
value.prizeStarCount
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : GiveawayCreated {
|
||||||
|
val Common = this
|
||||||
|
override val prizeStarCount: Int?
|
||||||
|
get() = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,25 @@ import kotlinx.serialization.Serializable
|
|||||||
sealed interface GiveawayInfo {
|
sealed interface GiveawayInfo {
|
||||||
val selectionDate: TelegramDate
|
val selectionDate: TelegramDate
|
||||||
val onlyNewMembers: Boolean
|
val onlyNewMembers: Boolean
|
||||||
val premiumMonths: Int?
|
|
||||||
val additionalPrizeDescription: String?
|
val additionalPrizeDescription: String?
|
||||||
|
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
sealed interface OptionallyPremium : GiveawayInfo {
|
||||||
|
val premiumMonths: Int?
|
||||||
|
}
|
||||||
|
@Serializable
|
||||||
|
sealed interface Premium : OptionallyPremium {
|
||||||
|
override val premiumMonths: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
sealed interface OptionallyStars : GiveawayInfo {
|
||||||
|
val prizeStarCount: Int?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
sealed interface Stars : OptionallyStars {
|
||||||
|
override val prizeStarCount: Int
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ import kotlinx.serialization.encoding.Encoder
|
|||||||
|
|
||||||
@Serializable(GiveawayPublicResults.Companion::class)
|
@Serializable(GiveawayPublicResults.Companion::class)
|
||||||
sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId,
|
sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPreviewChatAndMessageId,
|
||||||
ReplyInfo.External.ContentVariant {
|
ReplyInfo.External.ContentVariant, GiveawayInfo.OptionallyStars, GiveawayInfo.OptionallyPremium {
|
||||||
val count: Int
|
val count: Int
|
||||||
val winners: List<PreviewUser>
|
val winners: List<PreviewUser>
|
||||||
val additionalChats: Int
|
val additionalChats: Int
|
||||||
@ -46,11 +46,20 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
@SerialName(prizeDescriptionField)
|
@SerialName(prizeDescriptionField)
|
||||||
override val additionalPrizeDescription: String? = null
|
override val additionalPrizeDescription: String? = null
|
||||||
@SerialName(premiumSubscriptionMonthCountField)
|
@SerialName(premiumSubscriptionMonthCountField)
|
||||||
override val premiumMonths: Int? = null
|
override val premiumMonths: Int?
|
||||||
|
get() = null
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int?
|
||||||
|
get() = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed interface Winners : GiveawayPublicResults {
|
||||||
|
override val prizeStarCount: Int?
|
||||||
|
get() = null
|
||||||
|
override val premiumMonths: Int?
|
||||||
|
get() = null
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Winners (
|
data class Premium (
|
||||||
@SerialName(chatsField)
|
@SerialName(chatsField)
|
||||||
override val chat: PreviewChat,
|
override val chat: PreviewChat,
|
||||||
@SerialName(giveawayMessageIdField)
|
@SerialName(giveawayMessageIdField)
|
||||||
@ -61,6 +70,8 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
override val count: Int,
|
override val count: Int,
|
||||||
@SerialName(winnersField)
|
@SerialName(winnersField)
|
||||||
override val winners: List<PreviewUser>,
|
override val winners: List<PreviewUser>,
|
||||||
|
@SerialName(premiumSubscriptionMonthCountField)
|
||||||
|
override val premiumMonths: Int,
|
||||||
@SerialName(additionalChatCountField)
|
@SerialName(additionalChatCountField)
|
||||||
override val additionalChats: Int = 0,
|
override val additionalChats: Int = 0,
|
||||||
@SerialName(unclaimedPrizeCountField)
|
@SerialName(unclaimedPrizeCountField)
|
||||||
@ -71,8 +82,69 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
override val publicWinners: Boolean = false,
|
override val publicWinners: Boolean = false,
|
||||||
@SerialName(prizeDescriptionField)
|
@SerialName(prizeDescriptionField)
|
||||||
override val additionalPrizeDescription: String? = null,
|
override val additionalPrizeDescription: String? = null,
|
||||||
|
) : Winners, GiveawayInfo.Premium {
|
||||||
|
@SerialName(wasRefundedField)
|
||||||
|
@Required
|
||||||
|
@EncodeDefault
|
||||||
|
override val refunded: Boolean = false
|
||||||
|
}
|
||||||
|
@Serializable
|
||||||
|
data class Stars (
|
||||||
|
@SerialName(chatsField)
|
||||||
|
override val chat: PreviewChat,
|
||||||
|
@SerialName(giveawayMessageIdField)
|
||||||
|
override val messageId: MessageId,
|
||||||
|
@SerialName(winnersSelectionDateField)
|
||||||
|
override val selectionDate: TelegramDate,
|
||||||
|
@SerialName(winnersCountField)
|
||||||
|
override val count: Int,
|
||||||
|
@SerialName(winnersField)
|
||||||
|
override val winners: List<PreviewUser>,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int,
|
||||||
|
@SerialName(additionalChatCountField)
|
||||||
|
override val additionalChats: Int = 0,
|
||||||
|
@SerialName(unclaimedPrizeCountField)
|
||||||
|
override val unclaimedCount: Int = 0,
|
||||||
|
@SerialName(onlyNewMembersField)
|
||||||
|
override val onlyNewMembers: Boolean = false,
|
||||||
|
@SerialName(hasPublicWinnersField)
|
||||||
|
override val publicWinners: Boolean = false,
|
||||||
|
@SerialName(prizeDescriptionField)
|
||||||
|
override val additionalPrizeDescription: String? = null,
|
||||||
|
) : Winners, GiveawayInfo.Stars {
|
||||||
|
@SerialName(wasRefundedField)
|
||||||
|
@Required
|
||||||
|
@EncodeDefault
|
||||||
|
override val refunded: Boolean = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Serializable
|
||||||
|
data class Unknown (
|
||||||
|
@SerialName(chatsField)
|
||||||
|
override val chat: PreviewChat,
|
||||||
|
@SerialName(giveawayMessageIdField)
|
||||||
|
override val messageId: MessageId,
|
||||||
|
@SerialName(winnersSelectionDateField)
|
||||||
|
override val selectionDate: TelegramDate,
|
||||||
|
@SerialName(winnersCountField)
|
||||||
|
override val count: Int,
|
||||||
|
@SerialName(winnersField)
|
||||||
|
override val winners: List<PreviewUser>,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
override val prizeStarCount: Int?,
|
||||||
@SerialName(premiumSubscriptionMonthCountField)
|
@SerialName(premiumSubscriptionMonthCountField)
|
||||||
override val premiumMonths: Int? = null
|
override val premiumMonths: Int?,
|
||||||
|
@SerialName(additionalChatCountField)
|
||||||
|
override val additionalChats: Int = 0,
|
||||||
|
@SerialName(unclaimedPrizeCountField)
|
||||||
|
override val unclaimedCount: Int = 0,
|
||||||
|
@SerialName(onlyNewMembersField)
|
||||||
|
override val onlyNewMembers: Boolean = false,
|
||||||
|
@SerialName(hasPublicWinnersField)
|
||||||
|
override val publicWinners: Boolean = false,
|
||||||
|
@SerialName(prizeDescriptionField)
|
||||||
|
override val additionalPrizeDescription: String? = null,
|
||||||
) : GiveawayPublicResults {
|
) : GiveawayPublicResults {
|
||||||
@SerialName(wasRefundedField)
|
@SerialName(wasRefundedField)
|
||||||
@Required
|
@Required
|
||||||
@ -105,7 +177,9 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
@SerialName(prizeDescriptionField)
|
@SerialName(prizeDescriptionField)
|
||||||
val additionalPrizeDescription: String? = null,
|
val additionalPrizeDescription: String? = null,
|
||||||
@SerialName(premiumSubscriptionMonthCountField)
|
@SerialName(premiumSubscriptionMonthCountField)
|
||||||
val premiumMonths: Int? = null
|
val premiumMonths: Int? = null,
|
||||||
|
@SerialName(prizeStarCountField)
|
||||||
|
val starsCount: Int? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object : KSerializer<GiveawayPublicResults> {
|
companion object : KSerializer<GiveawayPublicResults> {
|
||||||
@ -115,14 +189,13 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
override fun deserialize(decoder: Decoder): GiveawayPublicResults {
|
override fun deserialize(decoder: Decoder): GiveawayPublicResults {
|
||||||
val surrogate = Surrogate.serializer().deserialize(decoder)
|
val surrogate = Surrogate.serializer().deserialize(decoder)
|
||||||
|
|
||||||
return when (surrogate.refunded) {
|
return when {
|
||||||
true -> Refunded(
|
surrogate.refunded -> Refunded(
|
||||||
chat = surrogate.chat,
|
chat = surrogate.chat,
|
||||||
messageId = surrogate.messageId,
|
messageId = surrogate.messageId,
|
||||||
selectionDate = surrogate.selectionDate
|
selectionDate = surrogate.selectionDate
|
||||||
)
|
)
|
||||||
false -> {
|
surrogate.premiumMonths != null -> Winners.Premium(
|
||||||
Winners(
|
|
||||||
chat = surrogate.chat,
|
chat = surrogate.chat,
|
||||||
messageId = surrogate.messageId,
|
messageId = surrogate.messageId,
|
||||||
selectionDate = surrogate.selectionDate,
|
selectionDate = surrogate.selectionDate,
|
||||||
@ -135,7 +208,33 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
additionalPrizeDescription = surrogate.additionalPrizeDescription,
|
additionalPrizeDescription = surrogate.additionalPrizeDescription,
|
||||||
premiumMonths = surrogate.premiumMonths,
|
premiumMonths = surrogate.premiumMonths,
|
||||||
)
|
)
|
||||||
}
|
surrogate.starsCount != null -> Winners.Stars(
|
||||||
|
chat = surrogate.chat,
|
||||||
|
messageId = surrogate.messageId,
|
||||||
|
selectionDate = surrogate.selectionDate,
|
||||||
|
count = surrogate.count,
|
||||||
|
winners = surrogate.winners,
|
||||||
|
additionalChats = surrogate.additionalChats,
|
||||||
|
unclaimedCount = surrogate.unclaimedCount,
|
||||||
|
onlyNewMembers = surrogate.onlyNewMembers,
|
||||||
|
publicWinners = surrogate.publicWinners,
|
||||||
|
additionalPrizeDescription = surrogate.additionalPrizeDescription,
|
||||||
|
prizeStarCount = surrogate.starsCount,
|
||||||
|
)
|
||||||
|
else -> Unknown(
|
||||||
|
chat = surrogate.chat,
|
||||||
|
messageId = surrogate.messageId,
|
||||||
|
selectionDate = surrogate.selectionDate,
|
||||||
|
count = surrogate.count,
|
||||||
|
winners = surrogate.winners,
|
||||||
|
additionalChats = surrogate.additionalChats,
|
||||||
|
unclaimedCount = surrogate.unclaimedCount,
|
||||||
|
onlyNewMembers = surrogate.onlyNewMembers,
|
||||||
|
publicWinners = surrogate.publicWinners,
|
||||||
|
additionalPrizeDescription = surrogate.additionalPrizeDescription,
|
||||||
|
premiumMonths = surrogate.premiumMonths,
|
||||||
|
prizeStarCount = surrogate.starsCount,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,10 +251,52 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
|
|||||||
publicWinners = value.publicWinners,
|
publicWinners = value.publicWinners,
|
||||||
additionalPrizeDescription = value.additionalPrizeDescription,
|
additionalPrizeDescription = value.additionalPrizeDescription,
|
||||||
premiumMonths = value.premiumMonths,
|
premiumMonths = value.premiumMonths,
|
||||||
|
starsCount = value.prizeStarCount,
|
||||||
refunded = value.refunded
|
refunded = value.refunded
|
||||||
)
|
)
|
||||||
|
|
||||||
Surrogate.serializer().serialize(encoder, surrogate)
|
Surrogate.serializer().serialize(encoder, surrogate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Winners(
|
||||||
|
chat: PreviewChat,
|
||||||
|
messageId: MessageId,
|
||||||
|
selectionDate: TelegramDate,
|
||||||
|
count: Int,
|
||||||
|
winners: List<PreviewUser>,
|
||||||
|
additionalChats: Int = 0,
|
||||||
|
unclaimedCount: Int = 0,
|
||||||
|
onlyNewMembers: Boolean = false,
|
||||||
|
publicWinners: Boolean = false,
|
||||||
|
additionalPrizeDescription: String? = null,
|
||||||
|
premiumMonths: Int? = null
|
||||||
|
) = premiumMonths ?.let {
|
||||||
|
Winners.Premium(
|
||||||
|
chat = chat,
|
||||||
|
messageId = messageId,
|
||||||
|
selectionDate = selectionDate,
|
||||||
|
count = count,
|
||||||
|
winners = winners,
|
||||||
|
premiumMonths = premiumMonths,
|
||||||
|
additionalChats = additionalChats,
|
||||||
|
unclaimedCount = unclaimedCount,
|
||||||
|
onlyNewMembers = onlyNewMembers,
|
||||||
|
publicWinners = publicWinners,
|
||||||
|
additionalPrizeDescription = additionalPrizeDescription
|
||||||
|
)
|
||||||
|
} ?: Unknown(
|
||||||
|
chat = chat,
|
||||||
|
messageId = messageId,
|
||||||
|
selectionDate = selectionDate,
|
||||||
|
count = count,
|
||||||
|
winners = winners,
|
||||||
|
prizeStarCount = null,
|
||||||
|
premiumMonths = premiumMonths,
|
||||||
|
additionalChats = additionalChats,
|
||||||
|
unclaimedCount = unclaimedCount,
|
||||||
|
onlyNewMembers = onlyNewMembers,
|
||||||
|
publicWinners = publicWinners,
|
||||||
|
additionalPrizeDescription = additionalPrizeDescription
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user