commonMain.com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.ContentMessageConversations.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of TelegramBotAPI-extensions-utils-js Show documentation
Show all versions of TelegramBotAPI-extensions-utils-js Show documentation
Util extensions for more useful work with updates and other things
The newest version!
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull
import kotlin.reflect.KClass
fun Flow>.withContentType(contentType: KClass) = mapNotNull {
if (contentType.isInstance(it.content)) {
@Suppress("UNCHECKED_CAST")
it as ContentMessage
} else {
null
}
}
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)