diff --git a/CHANGELOG.md b/CHANGELOG.md index 242a45f9c3..8aadcf0fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ * All extensions like `CaptionedInput#toHtmlCaptions` * All helper extensions for `List` * All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe` + * `BotCommand` now more strictly check commands which passed to it + * Regex `BotCommandNameRegex` was added * `TelegramBotAPI-extensions-api`: * A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing * New `RequesstExecutor#setMyCommands` extension was added 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 0f52133bfb..f1b26eb5c8 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 @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.types +import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +val BotCommandNameRegex = Regex("[a-z_0-9]{1,32}") + @Serializable data class BotCommand( @SerialName(botCommandField) @@ -12,10 +15,13 @@ data class BotCommand( ) { init { if (command.length !in botCommandLengthLimit) { - error("Command size must be in range $botCommandLengthLimit, but actually have length ${command.length}") + throwRangeError("Command name size", botCommandLengthLimit, command.length) + } + if (!command.matches(BotCommandNameRegex)) { + error("Bot command must contains only lowercase English letters, digits and underscores, but incoming command was $command") } if (description.length !in botCommandDescriptionLimit) { - error("Command description size must be in range $botCommandDescriptionLimit, but actually have length ${description.length}") + throwRangeError("Command description size", botCommandDescriptionLimit, description.length) } } }