1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 03:28:44 +00:00

PollOption added

This commit is contained in:
InsanusMokrassar 2019-04-16 15:45:29 +08:00
parent c95c0a0ae0
commit 0af6e6ca15
4 changed files with 42 additions and 0 deletions

View File

@ -2,6 +2,8 @@
## 0.13.0 Telegram Polls ## 0.13.0 Telegram Polls
* `PollOption` added
## 0.12.0 Webhooks ## 0.12.0 Webhooks
* Added `DataRequest` interface which replace `Data` interface * Added `DataRequest` interface which replace `Data` interface

View File

@ -75,6 +75,7 @@ const val hasCustomCertificateField = "has_custom_certificate"
const val pendingUpdateCountField = "pending_update_count" const val pendingUpdateCountField = "pending_update_count"
const val lastErrorDateField = "last_error_date" const val lastErrorDateField = "last_error_date"
const val lastErrorMessageField = "last_error_message" const val lastErrorMessageField = "last_error_message"
const val votesCountField = "voter_count"
const val photoUrlField = "photo_url" const val photoUrlField = "photo_url"

View File

@ -0,0 +1,37 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.polls
import com.github.insanusmokrassar.TelegramBotAPI.types.textField
import com.github.insanusmokrassar.TelegramBotAPI.types.votesCountField
import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializable(PollOptionSerializer::class)
sealed class PollOption {
abstract val text: String
abstract val votes: Int
}
@Serializable
data class AnonymousPollOption (
@SerialName(textField)
override val text: String,
@SerialName(votesCountField)
override val votes: Int
) : PollOption()
object PollOptionSerializer : KSerializer<PollOption> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(PollOption::class.simpleName ?: "PollOption")
override fun deserialize(decoder: Decoder): PollOption = AnonymousPollOption.serializer().deserialize(
decoder
)
override fun serialize(encoder: Encoder, obj: PollOption) {
when (obj) {
is AnonymousPollOption -> AnonymousPollOption.serializer().serialize(
encoder,
obj
)
}
}
}

View File

@ -0,0 +1,2 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.polls.abstracts