1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

Merge pull request #274 from InsanusMokrassar/0.32.1

0.32.1
This commit is contained in:
InsanusMokrassar 2021-01-30 21:06:15 +06:00 committed by GitHub
commit b637d0d2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 20 deletions

View File

@ -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**

View File

@ -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

View File

@ -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<Boolean> {
override fun method(): String = "answerCallbackQuery"

View File

@ -16,7 +16,7 @@ data class AnswerInlineQuery(
@Serializable(InlineQueryAnswersResultsSerializer::class)
@SerialName(resultsField)
val results: List<InlineQueryResult> = emptyList(),
@SerialName(cachedTimeField)
@SerialName(cacheTimeField)
val cachedTime: Int? = null,
@SerialName(isPersonalField)
val isPersonal: Boolean? = null,

View File

@ -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"

View File

@ -9,6 +9,11 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import kotlin.reflect.KClass
private inline fun <reified T : MessageContent> Flow<ContentMessage<*>>.withContentType() = mapNotNull {
it.withContent<T>()
}
@Deprecated("This method will be removed in next major update")
fun <T : MessageContent> Flow<ContentMessage<*>>.withContentType(contentType: KClass<T>) = mapNotNull {
if (contentType.isInstance(it.content)) {
@Suppress("UNCHECKED_CAST")
@ -18,19 +23,19 @@ fun <T : MessageContent> Flow<ContentMessage<*>>.withContentType(contentType: KC
}
}
fun Flow<ContentMessage<*>>.onlyAnimationContentMessages() = withContentType(AnimationContent::class)
fun Flow<ContentMessage<*>>.onlyAudioContentMessages() = withContentType(AudioContent::class)
fun Flow<ContentMessage<*>>.onlyContactContentMessages() = withContentType(ContactContent::class)
fun Flow<ContentMessage<*>>.onlyDiceContentMessages() = withContentType(DiceContent::class)
fun Flow<ContentMessage<*>>.onlyDocumentContentMessages() = withContentType(DocumentContent::class)
fun Flow<ContentMessage<*>>.onlyGameContentMessages() = withContentType(GameContent::class)
fun Flow<ContentMessage<*>>.onlyInvoiceContentMessages() = withContentType(InvoiceContent::class)
fun Flow<ContentMessage<*>>.onlyLocationContentMessages() = withContentType(LocationContent::class)
fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType(PhotoContent::class)
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType(PollContent::class)
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType(StickerContent::class)
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType(TextContent::class)
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType(VenueContent::class)
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType(VideoContent::class)
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType(VideoNoteContent::class)
fun Flow<ContentMessage<*>>.onlyVoiceContentMessages() = withContentType(VoiceContent::class)
fun Flow<ContentMessage<*>>.onlyAnimationContentMessages() = withContentType<AnimationContent>()
fun Flow<ContentMessage<*>>.onlyAudioContentMessages() = withContentType<AudioContent>()
fun Flow<ContentMessage<*>>.onlyContactContentMessages() = withContentType<ContactContent>()
fun Flow<ContentMessage<*>>.onlyDiceContentMessages() = withContentType<DiceContent>()
fun Flow<ContentMessage<*>>.onlyDocumentContentMessages() = withContentType<DocumentContent>()
fun Flow<ContentMessage<*>>.onlyGameContentMessages() = withContentType<GameContent>()
fun Flow<ContentMessage<*>>.onlyInvoiceContentMessages() = withContentType<InvoiceContent>()
fun Flow<ContentMessage<*>>.onlyLocationContentMessages() = withContentType<LocationContent>()
fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType<PhotoContent>()
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType<PollContent>()
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType<StickerContent>()
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType<TextContent>()
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType<VenueContent>()
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType<VideoContent>()
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType<VideoNoteContent>()
fun Flow<ContentMessage<*>>.onlyVoiceContentMessages() = withContentType<VoiceContent>()

View File

@ -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 <reified T : MessageContent> ContentMessage<*>.withContent() = if (content is T) { this as ContentMessage<T> } else { null }
inline fun <reified T : MessageContent> ContentMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> CommonMessage<*>.withContent() = if (content is T) { this as CommonMessage<T> } else { null }
inline fun <reified T : MessageContent> CommonMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> PossiblySentViaBotCommonMessage<*>.withContent() = if (content is T) { this as PossiblySentViaBotCommonMessage<T> } else { null }
inline fun <reified T : MessageContent> PossiblySentViaBotCommonMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> ChannelMessage<*>.withContent() = if (content is T) { this as ChannelMessage<T> } else { null }
inline fun <reified T : MessageContent> ChannelMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> PrivateMessage<*>.withContent() = if (content is T) { this as PrivateMessage<T> } else { null }
inline fun <reified T : MessageContent> PrivateMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> PublicMessage<*>.withContent() = if (content is T) { this as PublicMessage<T> } else { null }
inline fun <reified T : MessageContent> PublicMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> GroupMessage<*>.withContent() = if (content is T) { this as GroupMessage<T> } else { null }
inline fun <reified T : MessageContent> GroupMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> FromChannelGroupMessage<*>.withContent() = if (content is T) { this as FromChannelGroupMessage<T> } else { null }
inline fun <reified T : MessageContent> FromChannelGroupMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> AnonymousGroupMessage<*>.withContent() = if (content is T) { this as AnonymousGroupMessage<T> } else { null }
inline fun <reified T : MessageContent> AnonymousGroupMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MessageContent> CommonGroupMessage<*>.withContent() = if (content is T) { this as CommonGroupMessage<T> } else { null }
inline fun <reified T : MessageContent> CommonGroupMessage<*>.requireWithContent() = withContent<T>()!!
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.withContent() = if (content is T) { this as MediaGroupMessage<T> } else { null }
inline fun <reified T : MediaGroupContent> MediaGroupMessage<*>.requireWithContent() = withContent<T>()!!