mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
rename MultilevelTextSource#textSources
This commit is contained in:
parent
0121e3a104
commit
b2fa7fee9d
@ -5,6 +5,8 @@
|
|||||||
* `Common`:
|
* `Common`:
|
||||||
* `Version`:
|
* `Version`:
|
||||||
* `MicroUtils`: `0.3.1` -> `0.3.2`
|
* `MicroUtils`: `0.3.1` -> `0.3.2`
|
||||||
|
* `Core`:
|
||||||
|
* `MultilevelTextSource#textSources` has been safely renamed to `subsources`
|
||||||
|
|
||||||
## 0.30.3
|
## 0.30.3
|
||||||
|
|
||||||
|
@ -36,7 +36,10 @@ interface MultilevelTextSource : TextSource {
|
|||||||
@Deprecated("Will be removed in near major release")
|
@Deprecated("Will be removed in near major release")
|
||||||
val textParts: List<TextPart>
|
val textParts: List<TextPart>
|
||||||
get() = textParts(0)
|
get() = textParts(0)
|
||||||
|
val subsources: List<TextSource>
|
||||||
|
@Deprecated("Will be removed in near major release", ReplaceWith("subsources"))
|
||||||
val textSources: List<TextSource>
|
val textSources: List<TextSource>
|
||||||
|
get() = subsources
|
||||||
}
|
}
|
||||||
|
|
||||||
data class TextPart(
|
data class TextPart(
|
||||||
@ -46,7 +49,7 @@ data class TextPart(
|
|||||||
|
|
||||||
fun List<TextPart>.justTextSources() = map { it.source }
|
fun List<TextPart>.justTextSources() = map { it.source }
|
||||||
fun List<TextSource>.makeString() = joinToString("") { 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>> {
|
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.boldMarkdown() }
|
override val asMarkdownSource: String by lazy { source.boldMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { boldMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { boldMarkdownV2() }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.cashTagMarkdown() }
|
override val asMarkdownSource: String by lazy { source.cashTagMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.emailMarkdown() }
|
override val asMarkdownSource: String by lazy { source.emailMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) }
|
override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.hashTagMarkdown() }
|
override val asMarkdownSource: String by lazy { source.hashTagMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.italicMarkdown() }
|
override val asMarkdownSource: String by lazy { source.italicMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { italicMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { italicMarkdownV2() }
|
||||||
|
@ -18,7 +18,7 @@ private val String.withoutCommercialAt
|
|||||||
*/
|
*/
|
||||||
data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
|
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.phoneMarkdown() }
|
override val asMarkdownSource: String by lazy { source.phoneMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asHtmlSource: String by lazy { strikethroughHTML() }
|
override val asHtmlSource: String by lazy { strikethroughHTML() }
|
||||||
override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() }
|
||||||
|
@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2
|
|||||||
data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
val user: User,
|
val user: User,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) }
|
override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) }
|
||||||
override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) }
|
override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) }
|
||||||
|
@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2
|
|||||||
*/
|
*/
|
||||||
data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||||
override val source: String,
|
override val source: String,
|
||||||
override val textSources: List<TextSource>
|
override val subsources: List<TextSource>
|
||||||
) : MultilevelTextSource {
|
) : MultilevelTextSource {
|
||||||
override val asMarkdownSource: String by lazy { source.underlineMarkdown() }
|
override val asMarkdownSource: String by lazy { source.underlineMarkdown() }
|
||||||
override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() }
|
override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() }
|
||||||
|
@ -83,19 +83,19 @@ private fun List<TextSource>.joinSubSourcesHtml() = joinToString("") {
|
|||||||
internal fun MultilevelTextSource.markdownV2Default(
|
internal fun MultilevelTextSource.markdownV2Default(
|
||||||
openControlSymbol: String,
|
openControlSymbol: String,
|
||||||
closeControlSymbol: String = openControlSymbol
|
closeControlSymbol: String = openControlSymbol
|
||||||
) = "$openControlSymbol${textSources.joinSubSourcesMarkdownV2()}$closeControlSymbol"
|
) = "$openControlSymbol${subsources.joinSubSourcesMarkdownV2()}$closeControlSymbol"
|
||||||
internal fun MultilevelTextSource.htmlDefault(
|
internal fun MultilevelTextSource.htmlDefault(
|
||||||
openControlSymbol: String,
|
openControlSymbol: String,
|
||||||
closeControlSymbol: String = openControlSymbol
|
closeControlSymbol: String = openControlSymbol
|
||||||
) = "<$openControlSymbol>${textSources.joinSubSourcesHtml()}</$closeControlSymbol>"
|
) = "<$openControlSymbol>${subsources.joinSubSourcesHtml()}</$closeControlSymbol>"
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.linkMarkdownV2(
|
internal fun MultilevelTextSource.linkMarkdownV2(
|
||||||
link: String
|
link: String
|
||||||
) = "[${textSources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})"
|
) = "[${subsources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})"
|
||||||
internal fun MultilevelTextSource.linkHTML(
|
internal fun MultilevelTextSource.linkHTML(
|
||||||
link: String
|
link: String
|
||||||
) = "<a href=\"${link.toHtml()}\">${textSources.joinSubSourcesHtml()}</a>"
|
) = "<a href=\"${link.toHtml()}\">${subsources.joinSubSourcesHtml()}</a>"
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.optionalPrefix(
|
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.boldHTML(): String = htmlDefault(htmlBoldControl)
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2()
|
internal fun MultilevelTextSource.cashTagMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
|
||||||
internal fun MultilevelTextSource.cashTagHTML(): String = textSources.joinSubSourcesHtml()
|
internal fun MultilevelTextSource.cashTagHTML(): String = subsources.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl)
|
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.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link)
|
||||||
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link)
|
||||||
|
|
||||||
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + textSources.joinSubSourcesMarkdownV2()
|
internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.joinSubSourcesMarkdownV2()
|
||||||
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + textSources.joinSubSourcesHtml()
|
internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when {
|
internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when {
|
||||||
source.startsWith("\\#") || source.startsWith("#") -> ""
|
source.startsWith("\\#") || source.startsWith("#") -> ""
|
||||||
else -> "\\#"
|
else -> "\\#"
|
||||||
} + textSources.joinSubSourcesMarkdownV2()
|
} + subsources.joinSubSourcesMarkdownV2()
|
||||||
internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + textSources.joinSubSourcesHtml()
|
internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + subsources.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2()
|
internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2()
|
||||||
internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml()
|
internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
|
||||||
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + textSources.joinSubSourcesMarkdownV2()
|
internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2()
|
||||||
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + textSources.joinSubSourcesHtml()
|
internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml()
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ fun List<TextPart>.testTextParts() {
|
|||||||
assertTrue (get(5).source is MentionTextSource)
|
assertTrue (get(5).source is MentionTextSource)
|
||||||
|
|
||||||
val boldSource = get(1).source as BoldTextSource
|
val boldSource = get(1).source as BoldTextSource
|
||||||
assertTrue (boldSource.textSources.first() is ItalicTextSource)
|
assertTrue (boldSource.subsources.first() is ItalicTextSource)
|
||||||
assertTrue (boldSource.textSources[1] is RegularTextSource)
|
assertTrue (boldSource.subsources[1] is RegularTextSource)
|
||||||
assertTrue (boldSource.textSources[2] is StrikethroughTextSource)
|
assertTrue (boldSource.subsources[2] is StrikethroughTextSource)
|
||||||
assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource)
|
assertTrue ((boldSource.subsources[2] as StrikethroughTextSource).subsources.first() is UnderlineTextSource)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user