From 76b25d719aa2c2f5382a7715027a4e71ced13f31 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 25 Apr 2020 09:48:23 +0600 Subject: [PATCH] explanation small utils and explanationLimit --- CHANGELOG.md | 3 +++ .../requests/send/polls/SendPoll.kt | 4 ++-- .../TelegramBotAPI/types/Common.kt | 4 +++- .../utils/CaptionAndTextSourcesToText.kt | 21 +++++++++++++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64413a336b..b1a8097910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index a107aeea6b..a87e377025 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -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") } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 68bd6b2fe2..441569f66d 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -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 diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt index 2e89721bed..76d3d65e9e 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionAndTextSourcesToText.kt @@ -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, @@ -65,6 +64,12 @@ fun List.toMarkdownTexts(): List = createMarkdownText( ) fun TextContent.toMarkdownTexts(): List = fullEntitiesList().toMarkdownTexts() +fun List.toMarkdownExplanations(): List = createMarkdownText( + this, + explanationLimit.last + 1 +) +fun ExplainedInput.toMarkdownExplanations(): List = fullEntitiesList().toMarkdownTexts() + fun createMarkdownV2Text( entities: List, @@ -83,6 +88,12 @@ fun List.toMarkdownV2Texts(): List = createMarkdownV2Text( ) fun TextContent.toMarkdownV2Texts(): List = fullEntitiesList().toMarkdownV2Texts() +fun List.toMarkdownV2Explanations(): List = createMarkdownV2Text( + this, + explanationLimit.last + 1 +) +fun ExplainedInput.toMarkdownV2Explanations(): List = fullEntitiesList().toMarkdownV2Texts() + fun createHtmlText( entities: List, @@ -101,4 +112,10 @@ fun List.toHtmlTexts(): List = createHtmlText( ) fun TextContent.toHtmlTexts(): List = fullEntitiesList().toHtmlTexts() +fun List.toHtmlExplanations(): List = createHtmlText( + this, + explanationLimit.last + 1 +) +fun ExplainedInput.toHtmlExplanations(): List = fullEntitiesList().toHtmlTexts() +