1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-23 00:57:13 +00:00

add openPeriodPollSecondsLimit and checks

This commit is contained in:
InsanusMokrassar 2020-04-24 19:46:47 +06:00
parent fbb2758bdb
commit 830ca8122d
3 changed files with 16 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* `openPeriodField`
* `closeDateField`
* Field `SendPoll#closeInfo` was added
* Range `openPeriodPollSecondsLimit` was added and used in all `SendPoll` requests for checking income data
* `SendQuizPoll` now able to use fields `caption` and `parseMode` for `explanation` functionality
* `quizPollExplanationLimit` was added for checking `QuizPoll` explanation size
* Field `TextLinkTextSource#url` was added

View File

@ -14,6 +14,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollCont
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions
import com.soywiz.klock.DateTime
import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
@ -118,6 +119,16 @@ fun Poll.createRequest(
)
}
private fun ScheduledCloseInfo.checkSendData() {
val span = when (this) {
is ExactScheduledCloseInfo -> (closeDateTime - DateTime.now()).seconds
is ApproximateScheduledCloseInfo -> openDuration.seconds
}.toInt()
if (span !in openPeriodPollSecondsLimit) {
error("Duration of autoclose for polls must be in range $openPeriodPollSecondsLimit, but was $span")
}
}
sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
abstract val question: String
@ -172,6 +183,7 @@ data class SendRegularPoll(
init {
checkPollInfo(question, options)
closeInfo ?.checkSendData()
}
}
@ -216,6 +228,7 @@ data class SendQuizPoll(
init {
checkPollInfo(question, options)
closeInfo ?.checkSendData()
val correctOptionIdRange = 0 .. options.size
if (correctOptionId !in correctOptionIdRange) {
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +

View File

@ -57,6 +57,8 @@ val botCommandsLimit = 0 .. 100
val quizPollExplanationLimit = 0 .. 200
val openPeriodPollSecondsLimit = 5 .. 600
const val chatIdField = "chat_id"
const val messageIdField = "message_id"
const val updateIdField = "update_id"