mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-06-29 04:47:48 +00:00
20 lines
730 B
Kotlin
20 lines
730 B
Kotlin
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandHTML
|
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.commandMarkdown
|
|
|
|
private val commandRegex = Regex("[/!][^@\\s]*")
|
|
|
|
data class BotCommandMessageEntity(
|
|
override val offset: Int,
|
|
override val length: Int,
|
|
override val sourceString: String
|
|
) : MessageEntity {
|
|
override val asMarkdownSource: String = sourceString.commandMarkdown()
|
|
override val asHtmlSource: String = sourceString.commandHTML()
|
|
|
|
val command: String by lazy {
|
|
commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!"
|
|
}
|
|
}
|