1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-10-23 00:00:09 +00:00

BotCommandNameRegex and strict check of incoming command

This commit is contained in:
2020-06-02 20:16:55 +06:00
parent ca9051920d
commit 7ede53fdbb
2 changed files with 10 additions and 2 deletions

View File

@@ -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)
}
}
}