mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
add openPeriodPollSecondsLimit and checks
This commit is contained in:
parent
fbb2758bdb
commit
830ca8122d
@ -14,6 +14,7 @@
|
|||||||
* `openPeriodField`
|
* `openPeriodField`
|
||||||
* `closeDateField`
|
* `closeDateField`
|
||||||
* Field `SendPoll#closeInfo` was added
|
* 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
|
* `SendQuizPoll` now able to use fields `caption` and `parseMode` for `explanation` functionality
|
||||||
* `quizPollExplanationLimit` was added for checking `QuizPoll` explanation size
|
* `quizPollExplanationLimit` was added for checking `QuizPoll` explanation size
|
||||||
* Field `TextLinkTextSource#url` was added
|
* Field `TextLinkTextSource#url` was added
|
||||||
|
@ -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.types.polls.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
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>>,
|
sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
||||||
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
|
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
|
||||||
abstract val question: String
|
abstract val question: String
|
||||||
@ -172,6 +183,7 @@ data class SendRegularPoll(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
checkPollInfo(question, options)
|
checkPollInfo(question, options)
|
||||||
|
closeInfo ?.checkSendData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +228,7 @@ data class SendQuizPoll(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
checkPollInfo(question, options)
|
checkPollInfo(question, options)
|
||||||
|
closeInfo ?.checkSendData()
|
||||||
val correctOptionIdRange = 0 .. options.size
|
val correctOptionIdRange = 0 .. options.size
|
||||||
if (correctOptionId !in correctOptionIdRange) {
|
if (correctOptionId !in correctOptionIdRange) {
|
||||||
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
|
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
|
||||||
|
@ -57,6 +57,8 @@ val botCommandsLimit = 0 .. 100
|
|||||||
|
|
||||||
val quizPollExplanationLimit = 0 .. 200
|
val quizPollExplanationLimit = 0 .. 200
|
||||||
|
|
||||||
|
val openPeriodPollSecondsLimit = 5 .. 600
|
||||||
|
|
||||||
const val chatIdField = "chat_id"
|
const val chatIdField = "chat_id"
|
||||||
const val messageIdField = "message_id"
|
const val messageIdField = "message_id"
|
||||||
const val updateIdField = "update_id"
|
const val updateIdField = "update_id"
|
||||||
|
Loading…
Reference in New Issue
Block a user