updates in caption and text lengths

This commit is contained in:
InsanusMokrassar 2020-06-01 11:44:58 +06:00
parent 7cd5666e88
commit ab9ceba41c
5 changed files with 19 additions and 13 deletions

View File

@ -52,8 +52,7 @@
### 0.27.5
* `TelegramotAPI`:
* Fix: `SendTextMessage` will correctly check the length of incoming text
* Constant `maxTextLength` was added
* Fix: for sending requests caption and text lengths limits were updated
### 0.27.4

View File

@ -9,6 +9,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
import kotlinx.serialization.*
internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
@ -36,8 +37,8 @@ data class SendTextMessage(
DisableWebPagePreview
{
init {
if (text.length > maxTextLength) {
throw IllegalArgumentException("Text length must be less than $maxTextLength, but was ${text.length}")
if (text.length !in textLength) {
throwRangeError("Text length", textLength, text.length)
}
}

View File

@ -26,9 +26,8 @@ typealias LongSeconds = Long
val getUpdatesLimit = 1 .. 100
val callbackQueryAnswerLength = 0 until 200
val captionLength = 0 until 1024
val textLength = 0 until 4096
val maxTextLength = textLength.last + 1
val captionLength = 0 .. 1024
val textLength = 1 .. 4096
val userProfilePhotosRequestLimit = 0 .. 100
val chatTitleLength = 1 until 255
val chatDescriptionLength = 0 until 256

View File

@ -8,7 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.fullEnti
fun createFormattedText(
entities: FullTextSourcesList,
partLength: Int = maxTextLength,
partLength: Int = textLength.last,
mode: ParseMode = MarkdownParseMode
): List<String> {
val texts = mutableListOf<String>()
@ -49,7 +49,7 @@ fun createFormattedText(
fun createMarkdownText(
entities: FullTextSourcesList,
partLength: Int = maxTextLength
partLength: Int = textLength.last
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
fun FullTextSourcesList.toMarkdownCaptions(): List<String> = createMarkdownText(
@ -60,7 +60,7 @@ fun CaptionedInput.toMarkdownCaptions(): List<String> = fullEntitiesList().toMar
fun FullTextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
this,
maxTextLength
textLength.last
)
fun TextContent.toMarkdownTexts(): List<String> = fullEntitiesList().toMarkdownTexts()
@ -73,7 +73,7 @@ fun ExplainedInput.toMarkdownExplanations(): List<String> = fullEntitiesList().t
fun createMarkdownV2Text(
entities: FullTextSourcesList,
partLength: Int = maxTextLength
partLength: Int = textLength.last
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
fun FullTextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
@ -84,7 +84,7 @@ fun CaptionedInput.toMarkdownV2Captions(): List<String> = fullEntitiesList().toM
fun FullTextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
this,
maxTextLength
textLength.last
)
fun TextContent.toMarkdownV2Texts(): List<String> = fullEntitiesList().toMarkdownV2Texts()
@ -108,7 +108,7 @@ fun CaptionedInput.toHtmlCaptions(): List<String> = fullEntitiesList().toHtmlCap
fun FullTextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
this,
maxTextLength
textLength.last
)
fun TextContent.toHtmlTexts(): List<String> = fullEntitiesList().toHtmlTexts()

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
internal fun throwRangeError(
valueName: String,
range: IntRange,
actualValue: Int
): Nothing = error("$valueName must be in range $range, but was $actualValue")