diff --git a/CHANGELOG.md b/CHANGELOG.md index 4efa9e9eb8..43a61ec3df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ ### 0.26.1 +* `TelegramBotAPI`: + * `BotCommand` now will check and throw error in case when command or description lengths is/are incorrect + ## 0.25.0 * Common: diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt index 1e3e9ee01d..0f52133bfb 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt @@ -9,4 +9,13 @@ data class BotCommand( val command: String, @SerialName(descriptionField) val description: String -) +) { + init { + if (command.length !in botCommandLengthLimit) { + error("Command size must be in range $botCommandLengthLimit, but actually have length ${command.length}") + } + if (description.length !in botCommandDescriptionLimit) { + error("Command description size must be in range $botCommandDescriptionLimit, but actually have length ${description.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 97b58db5d1..d0142f6a8b 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 @@ -49,7 +49,8 @@ val customTitleLength = 0 .. 16 val diceResultLimit = 1 .. 6 -val botCommandLimit = 1 .. 32 +val botCommandLengthLimit = 1 .. 32 +val botCommandLimit = botCommandLengthLimit val botCommandDescriptionLimit = 3 .. 256 val botCommandsLimit = 0 .. 100