From a0a93646e4e84d69f1ac5a0179bcd8bd881da0e3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 23 Jan 2019 12:15:57 +0800 Subject: [PATCH] 0.8.5 --- CHANGELOG | 14 ++++++++++---- build.gradle | 2 +- .../types/MessageEntity/MessageEntity.kt | 4 +++- .../TelegramBotAPI/utils/CaptionSourcer.kt | 5 +++-- .../TelegramBotAPI/utils/extensions/String.kt | 11 +++++++++++ 5 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt diff --git a/CHANGELOG b/CHANGELOG index 4a4c2f58d8..58d0d932f2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,22 +1,22 @@ # TelegramBotAPI changelog -## 0.8.1 +### 0.8.1 * Update `MediaGroupMessage` interface * Add implementation of `MediaGroupMessage` * Add generating of `MediaGroupMessage` in `RawMessage` -## 0.8.2 +### 0.8.2 * Add `FromUserMessage` which must be implemented in all messages realisations which have `user` field * Add `CommonMediaGroupMessage` which in fact extension of `MediaGroupMessage` with implementation of `FromUserMessage` * `CommonMessageImpl` now implementing `FromUserMessage` -## 0.8.3 +### 0.8.3 * Now `ForwardedMessage` contains nullable `from` -## 0.8.4 +### 0.8.4 * Added `createMarkdownText` and extensions for `CaptionedMediaContent` and `TextContent` * Added `ResendableContent` and realize in different contents @@ -36,3 +36,9 @@ * Now `Update` is untyped and data is `Any` * Media groups now are separated type of updates and you can subscribe on that receiving directly * Now `AdministratorChatMember` is interface and `CreatorChatMember` implement it + +### 0.8.5 + +* Add extension `String#toMarkdown` +* Fix of inserting of text when create Markdown-adapted text from text and text entities +* Fix default realisation of MessageEntity#asMarkdownSource diff --git a/build.gradle b/build.gradle index 045922e9ed..679e579617 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.8.4" +project.version = "0.8.5" project.group = "com.github.insanusmokrassar" buildscript { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt index 5c181d7fbf..96bfc85cc7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/MessageEntity.kt @@ -1,10 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity +import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown + interface MessageEntity { val offset: Int val length: Int val sourceString: String val asMarkdownSource: String - get() = sourceString + get() = sourceString.toMarkdown() } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionSourcer.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionSourcer.kt index 2af9230a2b..45221f7716 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionSourcer.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/CaptionSourcer.kt @@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent +import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown fun createMarkdownText( text: String, @@ -12,7 +13,7 @@ fun createMarkdownText( var offset = 0 for (entity in messageEntities) { builder.append( - text.substring(offset until entity.offset) + text.substring(offset until entity.offset).toMarkdown() ) builder.append( entity.asMarkdownSource @@ -20,7 +21,7 @@ fun createMarkdownText( offset += entity.length } builder.append( - text.substring(offset) + text.substring(offset).toMarkdown() ) return builder.toString() } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt new file mode 100644 index 0000000000..30584c0c7b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/String.kt @@ -0,0 +1,11 @@ +package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions + +fun String.toMarkdown(): String { + return replace( + "*", + "\\*" + ).replace( + "_", + "\\_" + ) +}