mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
BotCommandNameRegex and strict check of incoming command
This commit is contained in:
parent
ca9051920d
commit
7ede53fdbb
@ -63,6 +63,8 @@
|
|||||||
* All extensions like `CaptionedInput#toHtmlCaptions`
|
* All extensions like `CaptionedInput#toHtmlCaptions`
|
||||||
* All helper extensions for `List<BaseMessageUpdate>`
|
* All helper extensions for `List<BaseMessageUpdate>`
|
||||||
* All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
* All `RequestsExecutor#executeAsync` and `RequestsExecutor#executeUnsafe`
|
||||||
|
* `BotCommand` now more strictly check commands which passed to it
|
||||||
|
* Regex `BotCommandNameRegex` was added
|
||||||
* `TelegramBotAPI-extensions-api`:
|
* `TelegramBotAPI-extensions-api`:
|
||||||
* A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing
|
* A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing
|
||||||
* New `RequesstExecutor#setMyCommands` extension was added
|
* New `RequesstExecutor#setMyCommands` extension was added
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
val BotCommandNameRegex = Regex("[a-z_0-9]{1,32}")
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BotCommand(
|
data class BotCommand(
|
||||||
@SerialName(botCommandField)
|
@SerialName(botCommandField)
|
||||||
@ -12,10 +15,13 @@ data class BotCommand(
|
|||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
if (command.length !in botCommandLengthLimit) {
|
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) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user