1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

rename MultilevelTextSource#textSources

This commit is contained in:
InsanusMokrassar 2020-11-12 16:37:17 +06:00
parent 0121e3a104
commit b2fa7fee9d
14 changed files with 34 additions and 29 deletions

View File

@ -5,6 +5,8 @@
* `Common`:
* `Version`:
* `MicroUtils`: `0.3.1` -> `0.3.2`
* `Core`:
* `MultilevelTextSource#textSources` has been safely renamed to `subsources`
## 0.30.3

View File

@ -36,7 +36,10 @@ interface MultilevelTextSource : TextSource {
@Deprecated("Will be removed in near major release")
val textParts: List<TextPart>
get() = textParts(0)
val subsources: List<TextSource>
@Deprecated("Will be removed in near major release", ReplaceWith("subsources"))
val textSources: List<TextSource>
get() = subsources
}
data class TextPart(
@ -46,7 +49,7 @@ data class TextPart(
fun List<TextPart>.justTextSources() = map { it.source }
fun List<TextSource>.makeString() = joinToString("") { it.source }
internal fun MultilevelTextSource.textParts(offset: Int): List<TextPart> = textSources.toTextParts(offset)
internal fun MultilevelTextSource.textParts(offset: Int): List<TextPart> = subsources.toTextParts(offset)
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
if (isEmpty()) {
return emptyList()

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2
*/
data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.boldMarkdown() }
override val asMarkdownV2Source: String by lazy { boldMarkdownV2() }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2
*/
data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.cashTagMarkdown() }
override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2
*/
data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.emailMarkdown() }
override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2
*/
data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.hashTagMarkdown() }
override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2
*/
data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.italicMarkdown() }
override val asMarkdownV2Source: String by lazy { italicMarkdownV2() }

View File

@ -18,7 +18,7 @@ private val String.withoutCommercialAt
*/
data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2
*/
data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.phoneMarkdown() }
override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2
*/
data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asHtmlSource: String by lazy { strikethroughHTML() }
override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() }

View File

@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2
data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
val user: User,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) }
override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) }

View File

@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2
*/
data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String,
override val textSources: List<TextSource>
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.underlineMarkdown() }
override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() }

View File

@ -83,19 +83,19 @@ private fun List<TextSource>.joinSubSourcesHtml() = joinToString("") {
internal fun MultilevelTextSource.markdownV2Default(
openControlSymbol: String,
closeControlSymbol: String = openControlSymbol
) = "$openControlSymbol${textSources.joinSubSourcesMarkdownV2()}$closeControlSymbol"
) = "$openControlSymbol${subsources.joinSubSourcesMarkdownV2()}$closeControlSymbol"
internal fun MultilevelTextSource.htmlDefault(
openControlSymbol: String,
closeControlSymbol: String = openControlSymbol
) = "<$openControlSymbol>${textSources.joinSubSourcesHtml()}</$closeControlSymbol>"
) = "<$openControlSymbol>${subsources.joinSubSourcesHtml()}</$closeControlSymbol>"
internal fun MultilevelTextSource.linkMarkdownV2(
link: String
) = "[${textSources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})"
) = "[${subsources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})"
internal fun MultilevelTextSource.linkHTML(
link: String
) = "<a href=\"${link.toHtml()}\">${textSources.joinSubSourcesHtml()}</a>"
) = "<a href=\"${link.toHtml()}\">${subsources.joinSubSourcesHtml()}</a>"
internal fun MultilevelTextSource.optionalPrefix(
@ -116,8 +116,8 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m
internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl)
internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.cashTagHTML(): String = textSources.joinSubSourcesHtml()
internal fun MultilevelTextSource.cashTagMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.cashTagHTML(): String = subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl)
@ -135,21 +135,21 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde
internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + textSources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + textSources.joinSubSourcesHtml()
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when {
source.startsWith("\\#") || source.startsWith("#") -> ""
else -> "\\#"
} + textSources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + textSources.joinSubSourcesHtml()
} + subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml()
internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml()
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + textSources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + textSources.joinSubSourcesHtml()
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2()
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml()

View File

@ -49,8 +49,8 @@ fun List<TextPart>.testTextParts() {
assertTrue (get(5).source is MentionTextSource)
val boldSource = get(1).source as BoldTextSource
assertTrue (boldSource.textSources.first() is ItalicTextSource)
assertTrue (boldSource.textSources[1] is RegularTextSource)
assertTrue (boldSource.textSources[2] is StrikethroughTextSource)
assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource)
assertTrue (boldSource.subsources.first() is ItalicTextSource)
assertTrue (boldSource.subsources[1] is RegularTextSource)
assertTrue (boldSource.subsources[2] is StrikethroughTextSource)
assertTrue ((boldSource.subsources[2] as StrikethroughTextSource).subsources.first() is UnderlineTextSource)
}