1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 00:03:48 +00:00
This commit is contained in:
InsanusMokrassar 2019-01-23 12:15:57 +08:00
parent c6e7111ff5
commit a0a93646e4
5 changed files with 28 additions and 8 deletions

View File

@ -1,22 +1,22 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 0.8.1 ### 0.8.1
* Update `MediaGroupMessage` interface * Update `MediaGroupMessage` interface
* Add implementation of `MediaGroupMessage` * Add implementation of `MediaGroupMessage`
* Add generating of `MediaGroupMessage` in `RawMessage` * 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 `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` * Add `CommonMediaGroupMessage` which in fact extension of `MediaGroupMessage` with implementation of `FromUserMessage`
* `CommonMessageImpl` now implementing `FromUserMessage` * `CommonMessageImpl` now implementing `FromUserMessage`
## 0.8.3 ### 0.8.3
* Now `ForwardedMessage` contains nullable `from` * Now `ForwardedMessage` contains nullable `from`
## 0.8.4 ### 0.8.4
* Added `createMarkdownText` and extensions for `CaptionedMediaContent` and `TextContent` * Added `createMarkdownText` and extensions for `CaptionedMediaContent` and `TextContent`
* Added `ResendableContent` and realize in different contents * Added `ResendableContent` and realize in different contents
@ -36,3 +36,9 @@
* Now `Update` is untyped and data is `Any` * Now `Update` is untyped and data is `Any`
* Media groups now are separated type of updates and you can subscribe on that receiving directly * Media groups now are separated type of updates and you can subscribe on that receiving directly
* Now `AdministratorChatMember` is interface and `CreatorChatMember` implement it * 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

View File

@ -1,4 +1,4 @@
project.version = "0.8.4" project.version = "0.8.5"
project.group = "com.github.insanusmokrassar" project.group = "com.github.insanusmokrassar"
buildscript { buildscript {

View File

@ -1,10 +1,12 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
interface MessageEntity { interface MessageEntity {
val offset: Int val offset: Int
val length: Int val length: Int
val sourceString: String val sourceString: String
val asMarkdownSource: String val asMarkdownSource: String
get() = sourceString get() = sourceString.toMarkdown()
} }

View File

@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity 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.TextContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent
import com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.toMarkdown
fun createMarkdownText( fun createMarkdownText(
text: String, text: String,
@ -12,7 +13,7 @@ fun createMarkdownText(
var offset = 0 var offset = 0
for (entity in messageEntities) { for (entity in messageEntities) {
builder.append( builder.append(
text.substring(offset until entity.offset) text.substring(offset until entity.offset).toMarkdown()
) )
builder.append( builder.append(
entity.asMarkdownSource entity.asMarkdownSource
@ -20,7 +21,7 @@ fun createMarkdownText(
offset += entity.length offset += entity.length
} }
builder.append( builder.append(
text.substring(offset) text.substring(offset).toMarkdown()
) )
return builder.toString() return builder.toString()
} }

View File

@ -0,0 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.extensions
fun String.toMarkdown(): String {
return replace(
"*",
"\\*"
).replace(
"_",
"\\_"
)
}