TextSource properties has been renamed

This commit is contained in:
InsanusMokrassar 2020-11-16 13:32:20 +06:00
parent 6650dd9cfe
commit c2032d21cd
22 changed files with 78 additions and 63 deletions

View File

@ -2,6 +2,12 @@
## 0.30.6
* `Core`
* `TextSource` properties has been renamed:
* `asMarkdownSource` -> `markdown`
* `asMarkdownV2Source` -> `markdownV2`
* `asHtmlSource` -> `html`
## 0.30.5
* `Common`:

View File

@ -14,13 +14,23 @@ typealias FullTextSourcesList = List<TextSource>
typealias FullTextPartsList = List<TextPart>
interface TextSource {
val asMarkdownSource: String
val asMarkdownV2Source: String
val asHtmlSource: String
val markdown: String
val markdownV2: String
val html: String
val source: String
val asText: String
get() = source
@Deprecated("Rename", ReplaceWith("markdown"))
val asMarkdownSource: String
get() = markdown
@Deprecated("Rename", ReplaceWith("markdownV2"))
val asMarkdownV2Source: String
get() = markdownV2
@Deprecated("Rename", ReplaceWith("html"))
val asHtmlSource: String
get() = html
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor)
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.boldMarkdown() }
override val asMarkdownV2Source: String by lazy { boldMarkdownV2() }
override val asHtmlSource: String by lazy { boldHTML() }
override val markdown: String by lazy { source.boldMarkdown() }
override val markdownV2: String by lazy { boldMarkdownV2() }
override val html: String by lazy { boldHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -18,9 +18,9 @@ data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstru
commandRegex.find(source) ?.value ?.substring(1) ?: source.substring(1)// skip first symbol like "/" or "!"
}
override val asMarkdownSource: String by lazy { source.commandMarkdown() }
override val asMarkdownV2Source: String by lazy { source.commandMarkdownV2() }
override val asHtmlSource: String by lazy { source.commandHTML() }
override val markdown: String by lazy { source.commandMarkdown() }
override val markdownV2: String by lazy { source.commandMarkdownV2() }
override val html: String by lazy { source.commandHTML() }
}
/**

View File

@ -13,9 +13,9 @@ data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.cashTagMarkdown() }
override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() }
override val asHtmlSource: String by lazy { cashTagHTML() }
override val markdown: String by lazy { source.cashTagMarkdown() }
override val markdownV2: String by lazy { cashTagMarkdownV2() }
override val html: String by lazy { cashTagHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ import dev.inmo.tgbotapi.utils.internal.codeMarkdownV2
data class CodeTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String
) : TextSource {
override val asMarkdownSource: String by lazy { source.codeMarkdown() }
override val asMarkdownV2Source: String by lazy { source.codeMarkdownV2() }
override val asHtmlSource: String by lazy { source.codeHTML() }
override val markdown: String by lazy { source.codeMarkdown() }
override val markdownV2: String by lazy { source.codeMarkdownV2() }
override val html: String by lazy { source.codeHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor)
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.emailMarkdown() }
override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) }
override val asHtmlSource: String by lazy { emailHTML(source) }
override val markdown: String by lazy { source.emailMarkdown() }
override val markdownV2: String by lazy { emailMarkdownV2(source) }
override val html: String by lazy { emailHTML(source) }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.hashTagMarkdown() }
override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() }
override val asHtmlSource: String by lazy { hashTagHTML() }
override val markdown: String by lazy { source.hashTagMarkdown() }
override val markdownV2: String by lazy { hashTagMarkdownV2() }
override val html: String by lazy { hashTagHTML() }
init {
if (!source.startsWith("#")) {

View File

@ -13,9 +13,9 @@ data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.italicMarkdown() }
override val asMarkdownV2Source: String by lazy { italicMarkdownV2() }
override val asHtmlSource: String by lazy { italicHTML() }
override val markdown: String by lazy { source.italicMarkdown() }
override val markdownV2: String by lazy { italicMarkdownV2() }
override val html: String by lazy { italicHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -20,9 +20,9 @@ data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.mentionMarkdown() }
override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() }
override val asHtmlSource: String by lazy { mentionHTML() }
override val markdown: String by lazy { source.mentionMarkdown() }
override val markdownV2: String by lazy { mentionMarkdownV2() }
override val html: String by lazy { mentionHTML() }
init {
if (!source.startsWith("@")) {

View File

@ -13,9 +13,9 @@ data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.phoneMarkdown() }
override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() }
override val asHtmlSource: String by lazy { phoneHTML() }
override val markdown: String by lazy { source.phoneMarkdown() }
override val markdownV2: String by lazy { phoneMarkdownV2() }
override val html: String by lazy { phoneHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class PreTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) c
override val source: String,
val language: String? = null
) : TextSource {
override val asMarkdownSource: String by lazy { source.preMarkdown(language) }
override val asMarkdownV2Source: String by lazy { source.preMarkdownV2(language) }
override val asHtmlSource: String by lazy { source.preHTML(language) }
override val markdown: String by lazy { source.preMarkdown(language) }
override val markdownV2: String by lazy { source.preMarkdownV2(language) }
override val html: String by lazy { source.preHTML(language) }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -12,9 +12,9 @@ import dev.inmo.tgbotapi.utils.internal.regularMarkdownV2
data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String
) : TextSource {
override val asMarkdownSource: String by lazy { source.regularMarkdown() }
override val asMarkdownV2Source: String by lazy { source.regularMarkdownV2() }
override val asHtmlSource: String by lazy { source.regularHtml() }
override val markdown: String by lazy { source.regularMarkdown() }
override val markdownV2: String by lazy { source.regularMarkdownV2() }
override val html: String by lazy { source.regularHtml() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceCons
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asHtmlSource: String by lazy { strikethroughHTML() }
override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() }
override val asMarkdownSource: String by lazy { source.strikethroughMarkdown() }
override val html: String by lazy { strikethroughHTML() }
override val markdownV2: String by lazy { strikethroughMarkdownV2() }
override val markdown: String by lazy { source.strikethroughMarkdown() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class TextLinkTextSource @RiskFeature(DirectInvocationOfTextSourceConstruct
override val source: String,
val url: String
) : TextSource {
override val asMarkdownSource: String by lazy { source.linkMarkdown(url) }
override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(url) }
override val asHtmlSource: String by lazy { source.linkHTML(url) }
override val markdown: String by lazy { source.linkMarkdown(url) }
override val markdownV2: String by lazy { source.linkMarkdownV2(url) }
override val html: String by lazy { source.linkHTML(url) }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -15,9 +15,9 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
val user: User,
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) }
override val asHtmlSource: String by lazy { textMentionHTML(user.id) }
override val markdown: String by lazy { source.textMentionMarkdown(user.id) }
override val markdownV2: String by lazy { textMentionMarkdownV2(user.id) }
override val html: String by lazy { textMentionHTML(user.id) }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -12,9 +12,9 @@ import dev.inmo.tgbotapi.utils.internal.linkMarkdownV2
data class URLTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
override val source: String
) : TextSource {
override val asMarkdownSource: String by lazy { source.linkMarkdown(source) }
override val asMarkdownV2Source: String by lazy { source.linkMarkdownV2(source) }
override val asHtmlSource: String by lazy { source.linkHTML(source) }
override val markdown: String by lazy { source.linkMarkdown(source) }
override val markdownV2: String by lazy { source.linkMarkdownV2(source) }
override val html: String by lazy { source.linkHTML(source) }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -13,9 +13,9 @@ data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstruc
override val source: String,
override val subsources: List<TextSource>
) : MultilevelTextSource {
override val asMarkdownSource: String by lazy { source.underlineMarkdown() }
override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() }
override val asHtmlSource: String by lazy { underlineHTML() }
override val markdown: String by lazy { source.underlineMarkdown() }
override val markdownV2: String by lazy { underlineMarkdownV2() }
override val html: String by lazy { underlineHTML() }
}
@Suppress("NOTHING_TO_INLINE")

View File

@ -15,9 +15,9 @@ internal fun createFormattedText(
val textBuilder = StringBuilder(partLength)
for (entity in entities) {
val string = when (mode) {
is MarkdownParseMode -> entity.asMarkdownSource
is MarkdownV2ParseMode -> entity.asMarkdownV2Source
is HTMLParseMode -> entity.asHtmlSource
is MarkdownParseMode -> entity.markdown
is MarkdownV2ParseMode -> entity.markdownV2
is HTMLParseMode -> entity.html
}
if (textBuilder.length + string.length > partLength) {
if (textBuilder.isNotEmpty()) {

View File

@ -73,11 +73,11 @@ internal fun List<TextPart>.shiftSourcesToTheLeft(shiftCount: Int = 1): List<Tex
}
private fun List<TextSource>.joinSubSourcesMarkdownV2() = joinToString("") {
it.asMarkdownV2Source
it.markdownV2
}
private fun List<TextSource>.joinSubSourcesHtml() = joinToString("") {
it.asHtmlSource
it.html
}
internal fun MultilevelTextSource.markdownV2Default(

View File

@ -4,7 +4,6 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.link
import dev.inmo.tgbotapi.types.ParseMode.*
import dev.inmo.tgbotapi.types.chat.abstracts.*
import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedChat
import dev.inmo.tgbotapi.types.chat.abstracts.extended.ExtendedPublicChat
import dev.inmo.tgbotapi.types.message.abstracts.Message
@ -92,17 +91,17 @@ val StickerSetName.stickerSetLink
@Deprecated("Use extension `stickerSetLink` + getting of `asMarkdownV2Source` property")
fun makeLinkToAddStickerSetInMarkdownV2(
stickerSetName: StickerSetName
) = stickerSetName.stickerSetLink.asMarkdownV2Source
) = stickerSetName.stickerSetLink.markdownV2
/**
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown]
*/
@Deprecated("Use extension `stickerSetLink` + getting of `asMarkdownSource` property")
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.asMarkdownSource
fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.markdown
/**
* @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML]
*/
@Deprecated("Use extension `stickerSetLink` + getting of `asHtmlSource` property")
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.asHtmlSource
fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) = stickerSetName.stickerSetLink.html
/**
* Create a link for adding of sticker set with name [stickerSetName]. Was added thanks to user Djaler and based on
* https://github.com/Djaler/evil-bot/blob/master/src/main/kotlin/com/github/djaler/evilbot/utils/StickerUtils.kt#L6-L8

View File

@ -15,9 +15,9 @@ fun createFormattedText(
val textBuilder = StringBuilder(partLength)
for (entity in entities) {
val string = when (mode) {
is MarkdownParseMode -> entity.asMarkdownSource
is MarkdownV2ParseMode -> entity.asMarkdownV2Source
is HTMLParseMode -> entity.asHtmlSource
is MarkdownParseMode -> entity.markdown
is MarkdownV2ParseMode -> entity.markdownV2
is HTMLParseMode -> entity.html
}
if (textBuilder.length + string.length > partLength) {
if (textBuilder.isNotEmpty()) {