1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

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 ### 0.27.5
* `TelegramotAPI`: * `TelegramotAPI`:
* Fix: `SendTextMessage` will correctly check the length of incoming text * Fix: for sending requests caption and text lengths limits were updated
* Constant `maxTextLength` was added
### 0.27.4 ### 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.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
import kotlinx.serialization.* import kotlinx.serialization.*
internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>> internal val TextContentMessageResultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
@ -36,8 +37,8 @@ data class SendTextMessage(
DisableWebPagePreview DisableWebPagePreview
{ {
init { init {
if (text.length > maxTextLength) { if (text.length !in textLength) {
throw IllegalArgumentException("Text length must be less than $maxTextLength, but was ${text.length}") throwRangeError("Text length", textLength, text.length)
} }
} }

View File

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

View File

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