1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/MentionTextSource.kt

27 lines
941 B
Kotlin
Raw Normal View History

package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources
2020-01-05 13:51:32 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.MultilevelTextSource
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.TextPart
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
private val String.withoutCommercialAt
get() = if (startsWith("@")) {
substring(1)
} else {
this
}
class MentionTextSource(
override val source: String,
textParts: List<TextPart>
) : MultilevelTextSource {
override val textParts: List<TextPart> by lazy {
source.withoutCommercialAt.fullListOfSubSource(
textParts.shiftSourcesToTheLeft(1)
)
}
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }
override val asHtmlSource: String by lazy { mentionHTML() }
}