diff --git a/CHANGELOG.md b/CHANGELOG.md index 74684b3d5a..98e10f58f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # TelegramBotAPI changelog +## 0.32.1 + +* `Core`: + * Fix of [#272](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/272) +* `Utils`: + * Fix of [#273](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/273) + ## 0.32.0 **THIS UPDATE CONTAINS BREAKING CHANGES** diff --git a/gradle.properties b/gradle.properties index 710eeb454a..a70f642b88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.23 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.32.0 +library_version=0.32.1 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerCallbackQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerCallbackQuery.kt index ecb76c60a9..00cb73f39a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerCallbackQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerCallbackQuery.kt @@ -16,7 +16,7 @@ data class AnswerCallbackQuery( val showAlert: Boolean? = null, @SerialName(urlField) val url: String? = null, - @SerialName(cachedTimeField) + @SerialName(cacheTimeField) val cachedTimeSeconds: Int? = null ) : SimpleRequest { override fun method(): String = "answerCallbackQuery" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerInlineQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerInlineQuery.kt index ef5a9aeb0c..c295a99dcc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerInlineQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerInlineQuery.kt @@ -16,7 +16,7 @@ data class AnswerInlineQuery( @Serializable(InlineQueryAnswersResultsSerializer::class) @SerialName(resultsField) val results: List = emptyList(), - @SerialName(cachedTimeField) + @SerialName(cacheTimeField) val cachedTime: Int? = null, @SerialName(isPersonalField) val isPersonal: Boolean? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 44c9955298..819fb35587 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -123,7 +123,7 @@ const val callbackQueryIdField = "callback_query_id" const val inlineQueryIdField = "inline_query_id" const val inlineKeyboardField = "inline_keyboard" const val showAlertField = "show_alert" -const val cachedTimeField = "cached_time" +const val cacheTimeField = "cache_time" const val foursquareIdField = "foursquare_id" const val foursquareTypeField = "foursquare_type" const val googlePlaceIdField = "google_place_id" diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt index ce980fe93a..bcdff2ce59 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt @@ -9,6 +9,11 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.mapNotNull import kotlin.reflect.KClass +private inline fun Flow>.withContentType() = mapNotNull { + it.withContent() +} + +@Deprecated("This method will be removed in next major update") fun Flow>.withContentType(contentType: KClass) = mapNotNull { if (contentType.isInstance(it.content)) { @Suppress("UNCHECKED_CAST") @@ -18,19 +23,19 @@ fun Flow>.withContentType(contentType: KC } } -fun Flow>.onlyAnimationContentMessages() = withContentType(AnimationContent::class) -fun Flow>.onlyAudioContentMessages() = withContentType(AudioContent::class) -fun Flow>.onlyContactContentMessages() = withContentType(ContactContent::class) -fun Flow>.onlyDiceContentMessages() = withContentType(DiceContent::class) -fun Flow>.onlyDocumentContentMessages() = withContentType(DocumentContent::class) -fun Flow>.onlyGameContentMessages() = withContentType(GameContent::class) -fun Flow>.onlyInvoiceContentMessages() = withContentType(InvoiceContent::class) -fun Flow>.onlyLocationContentMessages() = withContentType(LocationContent::class) -fun Flow>.onlyPhotoContentMessages() = withContentType(PhotoContent::class) -fun Flow>.onlyPollContentMessages() = withContentType(PollContent::class) -fun Flow>.onlyStickerContentMessages() = withContentType(StickerContent::class) -fun Flow>.onlyTextContentMessages() = withContentType(TextContent::class) -fun Flow>.onlyVenueContentMessages() = withContentType(VenueContent::class) -fun Flow>.onlyVideoContentMessages() = withContentType(VideoContent::class) -fun Flow>.onlyVideoNoteContentMessages() = withContentType(VideoNoteContent::class) -fun Flow>.onlyVoiceContentMessages() = withContentType(VoiceContent::class) +fun Flow>.onlyAnimationContentMessages() = withContentType() +fun Flow>.onlyAudioContentMessages() = withContentType() +fun Flow>.onlyContactContentMessages() = withContentType() +fun Flow>.onlyDiceContentMessages() = withContentType() +fun Flow>.onlyDocumentContentMessages() = withContentType() +fun Flow>.onlyGameContentMessages() = withContentType() +fun Flow>.onlyInvoiceContentMessages() = withContentType() +fun Flow>.onlyLocationContentMessages() = withContentType() +fun Flow>.onlyPhotoContentMessages() = withContentType() +fun Flow>.onlyPollContentMessages() = withContentType() +fun Flow>.onlyStickerContentMessages() = withContentType() +fun Flow>.onlyTextContentMessages() = withContentType() +fun Flow>.onlyVenueContentMessages() = withContentType() +fun Flow>.onlyVideoContentMessages() = withContentType() +fun Flow>.onlyVideoNoteContentMessages() = withContentType() +fun Flow>.onlyVoiceContentMessages() = withContentType() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt new file mode 100644 index 0000000000..be45e0b6f1 --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/WithContent.kt @@ -0,0 +1,39 @@ +@file:Suppress("UNCHECKED_CAST") + +package dev.inmo.tgbotapi.extensions.utils + +import dev.inmo.tgbotapi.types.message.abstracts.* +import dev.inmo.tgbotapi.types.message.content.abstracts.* + +inline fun ContentMessage<*>.withContent() = if (content is T) { this as ContentMessage } else { null } +inline fun ContentMessage<*>.requireWithContent() = withContent()!! + +inline fun CommonMessage<*>.withContent() = if (content is T) { this as CommonMessage } else { null } +inline fun CommonMessage<*>.requireWithContent() = withContent()!! + +inline fun PossiblySentViaBotCommonMessage<*>.withContent() = if (content is T) { this as PossiblySentViaBotCommonMessage } else { null } +inline fun PossiblySentViaBotCommonMessage<*>.requireWithContent() = withContent()!! + +inline fun ChannelMessage<*>.withContent() = if (content is T) { this as ChannelMessage } else { null } +inline fun ChannelMessage<*>.requireWithContent() = withContent()!! + +inline fun PrivateMessage<*>.withContent() = if (content is T) { this as PrivateMessage } else { null } +inline fun PrivateMessage<*>.requireWithContent() = withContent()!! + +inline fun PublicMessage<*>.withContent() = if (content is T) { this as PublicMessage } else { null } +inline fun PublicMessage<*>.requireWithContent() = withContent()!! + +inline fun GroupMessage<*>.withContent() = if (content is T) { this as GroupMessage } else { null } +inline fun GroupMessage<*>.requireWithContent() = withContent()!! + +inline fun FromChannelGroupMessage<*>.withContent() = if (content is T) { this as FromChannelGroupMessage } else { null } +inline fun FromChannelGroupMessage<*>.requireWithContent() = withContent()!! + +inline fun AnonymousGroupMessage<*>.withContent() = if (content is T) { this as AnonymousGroupMessage } else { null } +inline fun AnonymousGroupMessage<*>.requireWithContent() = withContent()!! + +inline fun CommonGroupMessage<*>.withContent() = if (content is T) { this as CommonGroupMessage } else { null } +inline fun CommonGroupMessage<*>.requireWithContent() = withContent()!! + +inline fun MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage } else { null } +inline fun MediaGroupMessage<*>.requireWithContent() = withContent()!!