1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

cashtag entity type was added

This commit is contained in:
InsanusMokrassar 2020-01-23 03:05:28 +06:00
parent 971589fe99
commit 4182d66f6e
5 changed files with 34 additions and 1 deletions

View File

@ -79,6 +79,8 @@ while they can work incorrectly
### 0.22.2 CashTag and independent updates handling
* `cashtag` entity type was added
## 0.21.0 TelegramBotAPI 4.5
* _**All `MessageEntity`'es now are replaced with `TextPart`**_

View File

@ -23,7 +23,7 @@ internal fun RawMessageEntity.asTextParts(source: String, subParts: List<TextPar
return when (type) {
"mention" -> MentionTextSource(sourceSubstring, shiftedSubParts)
"hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubParts)
"cashtag" -> TODO()
"cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubParts)
"bot_command" -> BotCommandTextSource(sourceSubstring, shiftedSubParts)
"url" -> URLTextSource(sourceSubstring)
"email" -> EMailTextSource(sourceSubstring, shiftedSubParts)

View File

@ -0,0 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
class CashTagTextSource(
source: String,
textParts: List<TextPart>
) : MultilevelTextSource {
override val textParts: List<TextPart> by lazy { source.fullListOfSubSource(textParts) }
override val asMarkdownSource: String by lazy { source.cashTagMarkdown() }
override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() }
override val asHtmlSource: String by lazy { cashTagHTML() }
}

View File

@ -107,6 +107,10 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m
internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl)
internal fun MultilevelTextSource.cashTagMarkdownV2(): String = "\\#${textParts.joinSubSourcesMarkdownV2()}"
internal fun MultilevelTextSource.cashTagHTML(): String = "#${textParts.joinSubSourcesHtml()}"
internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl)
internal fun MultilevelTextSource.italicHTML(): String = htmlDefault(htmlItalicControl)

View File

@ -145,6 +145,11 @@ fun String.regularMarkdownV2(): String = escapeMarkdownV2Common()
fun String.regularHtml(): String = toHtml()
fun String.cashTagMarkdown(): String = toMarkdown()
fun String.cashTagMarkdownV2(): String = escapeMarkdownV2Common()
fun String.cashTagHtml(): String = toHtml()
infix fun String.bold(parseMode: ParseMode): String = when (parseMode) {
is HTML -> boldHTML()
is Markdown -> boldMarkdown()
@ -230,3 +235,9 @@ infix fun String.regular(parseMode: ParseMode): String = when (parseMode) {
is Markdown -> regularMarkdown()
is MarkdownV2 -> regularMarkdownV2()
}
infix fun String.cashtag(parseMode: ParseMode): String = when (parseMode) {
is HTML -> cashTagHtml()
is Markdown -> cashTagMarkdown()
is MarkdownV2 -> cashTagMarkdownV2()
}