1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-24 19:18:44 +00:00

revoke rework of GiveawayPublicResults

This commit is contained in:
InsanusMokrassar 2024-09-07 00:02:09 +06:00
parent 6809b9d2ef
commit d347c94c8b

View File

@ -10,7 +10,7 @@ import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder 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, GiveawayInfo.OptionallyStars, GiveawayInfo.OptionallyPremium { ReplyInfo.External.ContentVariant, GiveawayInfo.OptionallyStars, GiveawayInfo.OptionallyPremium {
val count: Int val count: Int
val winners: List<PreviewUser> val winners: List<PreviewUser>
@ -53,13 +53,8 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
get() = null get() = null
} }
sealed interface Winners : GiveawayPublicResults {
override val prizeStarCount: Int?
get() = null
override val premiumMonths: Int?
get() = null
@Serializable @Serializable
data class Premium ( data class Winners(
@SerialName(chatsField) @SerialName(chatsField)
override val chat: PreviewChat, override val chat: PreviewChat,
@SerialName(giveawayMessageIdField) @SerialName(giveawayMessageIdField)
@ -70,81 +65,20 @@ 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(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,
@SerialName(premiumSubscriptionMonthCountField) @SerialName(premiumSubscriptionMonthCountField)
override val premiumMonths: Int, override val premiumMonths: Int? = null,
@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.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) @SerialName(prizeStarCountField)
override val prizeStarCount: Int, override val prizeStarCount: Int? = null,
@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)
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
@ -195,33 +129,7 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
messageId = surrogate.messageId, messageId = surrogate.messageId,
selectionDate = surrogate.selectionDate selectionDate = surrogate.selectionDate
) )
surrogate.premiumMonths != null -> Winners.Premium( else -> Winners(
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,
)
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, chat = surrogate.chat,
messageId = surrogate.messageId, messageId = surrogate.messageId,
selectionDate = surrogate.selectionDate, selectionDate = surrogate.selectionDate,
@ -257,46 +165,5 @@ sealed interface GiveawayPublicResults: GiveawayInfo, GiveawayResults, WithPrevi
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
)
} }
} }