1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

Update BotCommandTextSource.kt

This commit is contained in:
InsanusMokrassar 2022-10-13 23:30:34 +06:00 committed by GitHub
parent bd91d4a0c0
commit ac7bf60182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,14 +13,14 @@ private val commandRegex = Regex("[/!][^@\\s]*")
* @see botCommand * @see botCommand
*/ */
@Serializable @Serializable
data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor( data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String override val source: String
) : TextSource { ) : TextSource {
val command: String by lazy { val command: String by lazy {
commandRegex.find(source)?.value?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!" commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
} }
val username: Username? by lazy { val username: Username? by lazy {
Username(usernameRegex.find(source)?.value ?: return@lazy null) Username(usernameRegex.find(source) ?.value ?: return@lazy null)
} }
override val markdown: String by lazy { source.commandMarkdown() } override val markdown: String by lazy { source.commandMarkdown() }
@ -35,4 +35,4 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
inline fun botCommand(command: String) = BotCommandTextSource("/$command") inline fun botCommand(command: String) = BotCommandTextSource("/$command")
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun botCommand(botCommand: BotCommand) = botCommand(botCommand.command) inline fun botCommand(botCommand: BotCommand) = botCommand(botCommand.command)