explanation small utils and explanationLimit

This commit is contained in:
InsanusMokrassar 2020-04-25 09:48:23 +06:00
parent a4d077dd17
commit 76b25d719a
4 changed files with 27 additions and 5 deletions

View File

@ -57,6 +57,9 @@
* In `QuizPoll#caption` and `QuizPoll#captionEntities` are deprecated now
* Class `SendQuizPoll` now implement `ExplainedOutput`
* In `SendQuizPoll#caption` is deprecated now
* `explanationLimit` range was added as future replacement of `quizPollExplanationLimit`
* `quizPollExplanationLimit` now is deprecated
* Extensions `toMarkdownExplanations`, `toMarkdownV2Explanations` and `toHtmlExplanations` was added
* `TelegramBotAPI-extensions-api`:
* `sendQuizPoll` now is using `explanation` parameter instead of `caption`

View File

@ -237,8 +237,8 @@ data class SendQuizPoll(
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
"value is $correctOptionId")
}
if (explanation != null && explanation.length !in quizPollExplanationLimit) {
error("Quiz poll explanation size must be in range $quizPollExplanationLimit," +
if (explanation != null && explanation.length !in explanationLimit) {
error("Quiz poll explanation size must be in range $explanationLimit," +
"but actual explanation contains ${explanation.length} symbols")
}
}

View File

@ -55,7 +55,9 @@ val botCommandLimit = botCommandLengthLimit
val botCommandDescriptionLimit = 3 .. 256
val botCommandsLimit = 0 .. 100
val quizPollExplanationLimit = 0 .. 200
val explanationLimit = 0 .. 200
@Deprecated("Will be removed in near updates", ReplaceWith("explanationLimit"))
val quizPollExplanationLimit = explanationLimit
val openPeriodPollSecondsLimit = 5 .. 600

View File

@ -1,11 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
import com.github.insanusmokrassar.TelegramBotAPI.types.captionLength
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEntitiesList
import com.github.insanusmokrassar.TelegramBotAPI.types.textLength
fun createFormattedText(
entities: List<TextSource>,
@ -65,6 +64,12 @@ fun List<TextSource>.toMarkdownTexts(): List<String> = createMarkdownText(
)
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
fun List<TextSource>.toMarkdownExplanations(): List<String> = createMarkdownText(
this,
explanationLimit.last + 1
)
fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().toMarkdownTexts()
fun createMarkdownV2Text(
entities: List<TextSource>,
@ -83,6 +88,12 @@ fun List<TextSource>.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
)
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
fun List<TextSource>.toMarkdownV2Explanations(): List<String> = createMarkdownV2Text(
this,
explanationLimit.last + 1
)
fun ExplainedInput.toMarkdownV2Explanations(): List<String> = fullEntitiesList().toMarkdownV2Texts()
fun createHtmlText(
entities: List<TextSource>,
@ -101,4 +112,10 @@ fun List<TextSource>.toHtmlTexts(): List<String> = createHtmlText(
)
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()
fun List<TextSource>.toHtmlExplanations(): List<String> = createHtmlText(
this,
explanationLimit.last + 1
)
fun ExplainedInput.toHtmlExplanations(): List<String> = fullEntitiesList().toHtmlTexts()