diff --git a/CHANGELOG.md b/CHANGELOG.md index 119bb7644c..47b92c1537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # TelegramBotAPI changelog +## 0.30.6 + +* `Core` + * `TextSource` properties has been renamed: + * `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 * `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 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/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.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 ccb8857dea..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 @@ -1,13 +1,19 @@ 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.extended.ExtendedChat +import dev.inmo.tgbotapi.types.chat.abstracts.* +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 makeUsernameLink(username: String) = "$internalLinkBeginning/$username" +inline val Username.link + get() = makeUsernameLink(username) +inline fun makeLink(username: Username) = username.link + fun makeLinkToMessage( username: String, messageId: MessageIdentifier @@ -24,8 +30,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 +53,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.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.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.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 @@ -53,34 +110,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) +} 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()) {