From 7f7e82bbb07fefa1382c00055d262739fbe25c82 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 17:25:51 +0600 Subject: [PATCH] bot command entity command extracting fix --- CHANGELOG.md | 2 ++ .../types/MessageEntity/BotCommandMessageEntity.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a5d66c83..5b3f4a90da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ Other important changes: * Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request * `RawChat` boilerplate was removed and replaced by serializers +* `BotCommandMessageEntity#command` will not contain `/`/`!` parts and also will cut outside of command begin token (`/` +or `!`) and username token (`@`) or end of command (any space character) * `RequestsExecutor` now is `Closeable` * `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things like this diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt index cad8a5adfd..2454b2760f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/BotCommandMessageEntity.kt @@ -3,6 +3,8 @@ 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, @@ -12,6 +14,6 @@ data class BotCommandMessageEntity( override val asHtmlSource: String = sourceString.commandHTML() val command: String by lazy { - sourceString.substring(1)// skip first symbol like "/" or "!" + commandRegex.find(sourceString) ?.value ?.substring(1) ?: sourceString.substring(1)// skip first symbol like "/" or "!" } }