From af1d6d6f1a72ff6eeb481b382055e073c487a0dd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 15 Nov 2020 23:05:19 +0600 Subject: [PATCH 1/4] start 0.30.6 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 119bb7644c..f34555d3a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.30.6 + ## 0.30.5 * `Common`: diff --git a/gradle.properties b/gradle.properties index 0753fb19a2..f8fd51fe9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ micro_utils_version=0.4.0 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.30.5 +library_version=0.30.6 gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 From 6650dd9cfe8598568600124a5c40b6d4e9b5654c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 16 Nov 2020 13:22:08 +0600 Subject: [PATCH 2/4] reworking of links extension --- .../kotlin/dev/inmo/tgbotapi/types/User.kt | 4 +- .../types/chat/abstracts/PrivateChat.kt | 3 + .../utils/formatting/LinksFormatting.kt | 98 +++++++++++++------ 3 files changed, 71 insertions(+), 34 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt index f9d1e0ef05..bb9707428a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/User.kt @@ -10,9 +10,7 @@ import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.* @Serializable(UserSerializer::class) -sealed class User : PrivateChat { - abstract override val id: UserId -} +sealed class User : PrivateChat @Serializable data class CommonUser( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt index 65a254544b..d87404fdad 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/abstracts/PrivateChat.kt @@ -1,10 +1,13 @@ package dev.inmo.tgbotapi.types.chat.abstracts +import dev.inmo.tgbotapi.types.ChatId +import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.chat.PreviewChatSerializer import kotlinx.serialization.Serializable @Serializable(PreviewChatSerializer::class) interface PrivateChat : Chat, UsernameChat { + override val id: UserId val firstName: String val lastName: String } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index ccb8857dea..d02ed27b8a 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -1,13 +1,20 @@ package dev.inmo.tgbotapi.extensions.utils.formatting 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.PrivateChat -import dev.inmo.tgbotapi.types.chat.abstracts.UsernameChat +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 private const val internalLinkBeginning = "https://t.me" +fun makeLink(username: String) = "$internalLinkBeginning/$username" +inline val Username.link + get() = makeLink(username) +inline fun makeLink(username: Username) = username.link + fun makeLinkToMessage( username: String, messageId: MessageIdentifier @@ -24,8 +31,12 @@ fun makeLinkToMessage( private val linkIdRedundantPartRegex = Regex("^-100") private val usernameBeginSymbolRegex = Regex("^@") +/** + * Link which can be used as by any user to get access to [Message]. Returns null in case when there are no + * known way to build link (for [PrivateChat]s, for example) + */ fun makeLinkToMessage( - chat: ExtendedChat, + chat: Chat, messageId: MessageIdentifier ): String? { return when { @@ -43,8 +54,55 @@ fun makeLinkToMessage( } } +/** + * @see makeLinkToMessage + */ +val Message.link: String? + get() = makeLinkToMessage( + chat, + messageId + ) + +/** + * Link which can be used as by any user to get access to [Chat]. Returns null in case when there are no + * known way to build link + */ +val Chat.link: String? + get() { + if (this is UsernameChat) { + username ?.username ?.let { return it } + } + if (this is ExtendedPublicChat) { + inviteLink ?.let { return it } + } + if (this is PrivateChat) { + return id.link + } + return null + } + private const val stickerSetAddingLinkPrefix = "$internalLinkBeginning/addstickers" +val StickerSetName.stickerSetLink + get() = link(this, "$stickerSetAddingLinkPrefix/$this") + +/** + * @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2] + */ +@Deprecated("Use extension `stickerSetLink` + getting of `asMarkdownV2Source` property") +fun makeLinkToAddStickerSetInMarkdownV2( + stickerSetName: StickerSetName +) = stickerSetName.stickerSetLink.asMarkdownV2Source +/** + * @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 +/** + * @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 /** * 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 @@ -53,34 +111,12 @@ private const val stickerSetAddingLinkPrefix = "$internalLinkBeginning/addsticke * @see [makeLinkToAddStickerSetInMarkdown] * @see [makeLinkToAddStickerSetInHtml] */ +@Deprecated("Use extension `stickerSetLink` + getting of required property") fun makeLinkToAddStickerSet( stickerSetName: StickerSetName, parseMode: ParseMode -) = (stickerSetName to "$stickerSetAddingLinkPrefix/$stickerSetName").link( - parseMode -) - -/** - * @return Link for adding of sticker set with name [stickerSetName] with formatting for [MarkdownV2] - */ -fun makeLinkToAddStickerSetInMarkdownV2(stickerSetName: StickerSetName) = - makeLinkToAddStickerSet( - stickerSetName, - MarkdownV2 - ) -/** - * @return Link for adding of sticker set with name [stickerSetName] with formatting for [Markdown] - */ -fun makeLinkToAddStickerSetInMarkdown(stickerSetName: StickerSetName) = - makeLinkToAddStickerSet( - stickerSetName, - Markdown - ) -/** - * @return Link for adding of sticker set with name [stickerSetName] with formatting for [HTML] - */ -fun makeLinkToAddStickerSetInHtml(stickerSetName: StickerSetName) = - makeLinkToAddStickerSet( - stickerSetName, - HTML - ) +) = when (parseMode) { + MarkdownParseMode -> makeLinkToAddStickerSetInMarkdown(stickerSetName) + MarkdownV2ParseMode -> makeLinkToAddStickerSetInMarkdownV2(stickerSetName) + HTMLParseMode -> makeLinkToAddStickerSetInHtml(stickerSetName) +} From c2032d21cd9fd96fcf7cb6c4578ce169413750c3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 16 Nov 2020 13:32:20 +0600 Subject: [PATCH 3/4] TextSource properties has been renamed --- CHANGELOG.md | 6 ++++++ .../inmo/tgbotapi/CommonAbstracts/TextSource.kt | 16 +++++++++++++--- .../MessageEntity/textsources/BoldTextSource.kt | 6 +++--- .../textsources/BotCommandTextSource.kt | 6 +++--- .../textsources/CashTagTextSource.kt | 6 +++--- .../MessageEntity/textsources/CodeTextSource.kt | 6 +++--- .../MessageEntity/textsources/EMailTextSource.kt | 6 +++--- .../textsources/HashTagTextSource.kt | 6 +++--- .../textsources/ItalicTextSource.kt | 6 +++--- .../textsources/MentionTextSource.kt | 6 +++--- .../textsources/PhoneNumberTextSource.kt | 6 +++--- .../MessageEntity/textsources/PreTextSource.kt | 6 +++--- .../textsources/RegularTextSource.kt | 6 +++--- .../textsources/StrikethroughTextSource.kt | 6 +++--- .../textsources/TextLinkTextSource.kt | 6 +++--- .../textsources/TextMentionTextSource.kt | 6 +++--- .../MessageEntity/textsources/URLTextSource.kt | 6 +++--- .../textsources/UnderlineTextSource.kt | 6 +++--- .../internal/CaptionAndTextSourcesToText.kt | 6 +++--- .../internal/MultilevelTextSourceFormatting.kt | 4 ++-- .../utils/formatting/LinksFormatting.kt | 7 +++---- .../utils/formatting/ResendingTextFormatting.kt | 6 +++--- 22 files changed, 78 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f34555d3a0..a69be49063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.30.6 +* `Core` + * `TextSource` properties has been renamed: + * `asMarkdownSource` -> `markdown` + * `asMarkdownV2Source` -> `markdownV2` + * `asHtmlSource` -> `html` + ## 0.30.5 * `Common`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index 6f067adeff..08f70a5041 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -14,13 +14,23 @@ typealias FullTextSourcesList = List typealias FullTextPartsList = List 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index d5098f72f0..d4a05a7bc4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -13,9 +13,9 @@ data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index 8ca260ddf2..1923aa88bc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -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() } } /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 5b016c0fd1..4fa504f5ce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -13,9 +13,9 @@ data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index 86d4aae7cd..7935f01fc3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index 850cbefcd9..6de5d3ddce 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -13,9 +13,9 @@ data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 04af45a2e3..109ef54cbc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -13,9 +13,9 @@ data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo override val source: String, override val subsources: List ) : 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("#")) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 870fc8c7fc..92e71013c6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -13,9 +13,9 @@ data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index f56ca0a13e..421c89c7a3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -20,9 +20,9 @@ data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo override val source: String, override val subsources: List ) : 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("@")) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index c6950f0889..ea3bb8feae 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -13,9 +13,9 @@ data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstr override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index 8ec55f8deb..4c001f5387 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index d70f3d1129..1d78129ca6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index 58e8e18dbd..a1557d1b88 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -13,9 +13,9 @@ data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceCons override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index c0e3098dba..482fb7dcbc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index acf2902cfa..8fd7a50521 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -15,9 +15,9 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr val user: User, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index 4a5fb0825b..c2cad771c6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index db6dd52efa..4a7a799fdb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -13,9 +13,9 @@ data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstruc override val source: String, override val subsources: List ) : 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") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index a1c9d049af..5502e2e29a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -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()) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 31ef7e5136..ec8cf5ab7c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -73,11 +73,11 @@ internal fun List.shiftSourcesToTheLeft(shiftCount: Int = 1): List.joinSubSourcesMarkdownV2() = joinToString("") { - it.asMarkdownV2Source + it.markdownV2 } private fun List.joinSubSourcesHtml() = joinToString("") { - it.asHtmlSource + it.html } internal fun MultilevelTextSource.markdownV2Default( diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index d02ed27b8a..b05579fde5 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -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 diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt index a459574b13..ab62b4f1aa 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/ResendingTextFormatting.kt @@ -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()) { From 41bf3c7f0b986b32c73a68d984cf475f08def266 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 16 Nov 2020 16:25:10 +0600 Subject: [PATCH 4/4] filling of changelog and renaming of new function makeLink -> makeUsernameLink --- CHANGELOG.md | 11 +++++++++++ .../extensions/utils/formatting/LinksFormatting.kt | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69be49063..47b92c1537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ * `asMarkdownSource` -> `markdown` * `asMarkdownV2Source` -> `markdownV2` * `asHtmlSource` -> `html` + * `PrivateChat` override `id` property with type `UserId` + * Several new extensions and functions in links creation: + * New function `makeUsernameLink` with parameter `String` + * New extension `Username#link` and function `makeLink(Username)` + * Function `makeLinkToMessage` now able to get any type of chat + * New extension `Message#link` + * Old functions `makeLinkToAddStickerSet...` has been deprecated: + * `makeLinkToAddStickerSet` + * `makeLinkToAddStickerSetInMarkdownV2` + * `makeLinkToAddStickerSetInMarkdown` + * `makeLinkToAddStickerSetInHtml` ## 0.30.5 diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index b05579fde5..d18f6986c6 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -9,9 +9,9 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message private const val internalLinkBeginning = "https://t.me" -fun makeLink(username: String) = "$internalLinkBeginning/$username" +fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username" inline val Username.link - get() = makeLink(username) + get() = makeUsernameLink(username) inline fun makeLink(username: Username) = username.link fun makeLinkToMessage(