diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b8c7e45aa..faa8596f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # TelegramBotAPI changelog +## 5.1.1 + +* `Core`: + * Add opportunity to get user link with `makeUserLink` +* `BehaviourBuilder`: + * Fixes in content waiting expectators + ## 5.1.0 [Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support diff --git a/gradle.properties b/gradle.properties index 5290e27fd1..2b0c021b60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=5.1.0 +library_version=5.1.1 diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 86028c62a8..eed6617247 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -16,119 +16,176 @@ typealias CommonMessageToContentMapper = suspend CommonMessage.() -> T? @RiskFeature(lowLevelRiskFeatureMessage) suspend inline fun BehaviourContext.waitContent( initRequest: Request<*>? = null, - includeMediaGroups: Boolean = true, noinline errorFactory: NullableRequestBuilder<*> = { null } -): Flow = waitContentMessage(initRequest, includeMediaGroups, errorFactory).map { it.content } +): Flow = waitContentMessage(initRequest, errorFactory).map { it.content } +@Deprecated( + includeMediaGroupsDeprecationMessage, + ReplaceWith("waitAnyContent(initRequest, errorFactory)", "dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContent") +) suspend fun BehaviourContext.waitContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitAnyContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitContact( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitDice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitGame( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitLocation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitLiveLocation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitStaticLocation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitPoll( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitText( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitVenue( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAudioMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitAudioMediaGroupContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitDocumentMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitDocumentMediaGroupContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitMedia( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitMedia( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAnyMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitAnyMediaGroupContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitVisualMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitVisualMediaGroupContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitTextedMediaContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitTextedMediaContent( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitAnimation( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAudio( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitAudio( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitDocument( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitDocument( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitPhoto( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitPhoto( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitSticker( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitVideo( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContent(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContent(initRequest, errorFactory) +suspend fun BehaviourContext.waitVideo( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitVideoNote( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitVoice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) suspend fun BehaviourContext.waitInvoice( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContent(initRequest, false, errorFactory) +) = waitContent(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt index d908e016dd..8f0c069aae 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContentMessage.kt @@ -13,17 +13,20 @@ import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage import kotlinx.coroutines.flow.Flow +const val includeMediaGroupsDeprecationMessage = "includeMediaGroups is deprecated and its usage will not lead to any changes" typealias CommonMessageToCommonMessageMapper = suspend CommonMessage.() -> CommonMessage? @RiskFeature(lowLevelRiskFeatureMessage) suspend inline fun BehaviourContext.waitContentMessage( initRequest: Request<*>? = null, - includeMediaGroups: Boolean = true, noinline errorFactory: NullableRequestBuilder<*> = { null } ): Flow> = expectFlow( initRequest, errorFactory ) { + if (it !is BaseSentMessageUpdate) { + return@expectFlow emptyList() + } listOfNotNull((it.data as? CommonMessage<*>) ?.withContent()) } @@ -44,114 +47,172 @@ internal inline fun contentMessageConverter( if (content is T) this as CommonMessage else null } +@Deprecated( + includeMediaGroupsDeprecationMessage, + ReplaceWith("waitAnyContentMessage(initRequest, errorFactory)", "dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitAnyContentMessage") +) suspend fun BehaviourContext.waitContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitAnyContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitContactMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitDiceMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitGameMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitLocationMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitLiveLocationMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitStaticLocationMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitPollMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitTextMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitVenueMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAudioMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitAudioMediaGroupContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitMediaMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitMediaMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAnyMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitAnyMediaGroupContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitVisualMediaGroupContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitVisualMediaGroupContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitTextedMediaContentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = true -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitTextedMediaContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitAnimationMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitAudioMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitAudioMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitDocumentMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitDocumentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitPhotoMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitPhotoMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitStickerMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) +@Deprecated(includeMediaGroupsDeprecationMessage) suspend fun BehaviourContext.waitVideoMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, - includeMediaGroups: Boolean = false -) = waitContentMessage(initRequest, includeMediaGroups, errorFactory) + includeMediaGroups: Boolean +) = waitContentMessage(initRequest, errorFactory) +suspend fun BehaviourContext.waitVideoMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitVideoNoteMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitVoiceMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) suspend fun BehaviourContext.waitInvoiceMessage( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } -) = waitContentMessage(initRequest, false, errorFactory) +) = waitContentMessage(initRequest, errorFactory) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 625b8eaa4c..9165779964 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -14,6 +14,7 @@ import kotlinx.serialization.json.longOrNull import kotlin.jvm.JvmInline const val internalLinkBeginning = "https://t.me" +const val internalUserLinkBeginning = "tg://user?id=" @Serializable(ChatIdentifierSerializer::class) @ClassCastsIncluded @@ -66,7 +67,7 @@ fun IdChatIdentifier.toChatWithThreadId(threadId: MessageThreadId) = IdChatIdent */ @Warning("This API have restrictions in Telegram System") val Identifier.userLink: String - get() = "tg://user?id=$this" + get() = "$internalUserLinkBeginning$this" /** * https://core.telegram.org/bots/api#formatting-options */ diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/CommonMessageConversations.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/CommonMessageConversations.kt index 172dab74cc..541de0bea5 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/CommonMessageConversations.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/CommonMessageConversations.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.MessageContent import kotlinx.coroutines.flow.* @@ -34,3 +35,10 @@ fun > Flow.onlySentViaBot() = map fun > Flow.withoutSentViaBot() = filter { it !is PossiblySentViaBot || it.senderBot == null } + +/** + * Filter the messages and checking that incoming [ContentMessage.content] is not [MediaGroupContent] + */ +fun > Flow.withoutMediaGroups() = filter { + it.content !is MediaGroupContent<*> +} diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index d44a86475e..06fdef0e89 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -8,6 +8,7 @@ import io.ktor.http.encodeURLQueryComponent fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}" +fun makeUserLink(userId: UserId) = userId.userLink fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = identifier.toString().replace( linkIdRedundantPartRegex, ""