From 35dcd6ada755d4fefe10a583cae415baa71418dc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 31 May 2020 22:51:42 +0600 Subject: [PATCH] fix in SendMessage --- CHANGELOG.md | 4 ++++ .../TelegramBotAPI/requests/send/SendMessage.kt | 4 ++-- .../github/insanusmokrassar/TelegramBotAPI/types/Common.kt | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3fb794008..b9bd46603d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,10 @@ ### 0.27.5 +* `TelegramotAPI`: + * Fix: `SendTextMessage` will correctly check the length of incoming text + * Constant `maxTextLength` was added + ### 0.27.4 * `TelegramBotAPI-extensions-utils`: diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt index 8d91a0eb40..93622ddd01 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendMessage.kt @@ -36,8 +36,8 @@ data class SendTextMessage( DisableWebPagePreview { init { - if (text.length !in textLength) { - throw IllegalArgumentException("Text must be in $textLength range") + if (text.length > maxTextLength) { + throw IllegalArgumentException("Text length must be less than $maxTextLength, but was ${text.length}") } } 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 441569f66d..4ff6d9e89e 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 @@ -28,6 +28,7 @@ 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 userProfilePhotosRequestLimit = 0 .. 100 val chatTitleLength = 1 until 255 val chatDescriptionLength = 0 until 256