1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-25 02:58:10 +00:00
tgbotapi/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt

28 lines
1.0 KiB
Kotlin
Raw Normal View History

2020-03-30 15:40:36 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types
import com.github.insanusmokrassar.TelegramBotAPI.utils.throwRangeError
2020-03-30 15:40:36 +00:00
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
2020-08-19 06:14:28 +00:00
val BotCommandNameRegex = Regex("^[a-z_0-9]{${botCommandLengthLimit.first},${botCommandLengthLimit.last}}$")
2020-03-30 15:40:36 +00:00
@Serializable
data class BotCommand(
@SerialName(botCommandField)
val command: String,
@SerialName(descriptionField)
val description: String
2020-04-01 04:08:44 +00:00
) {
init {
if (command.length !in botCommandLengthLimit) {
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")
2020-04-01 04:08:44 +00:00
}
if (description.length !in botCommandDescriptionLimit) {
throwRangeError("Command description size", botCommandDescriptionLimit, description.length)
2020-04-01 04:08:44 +00:00
}
}
}