commonMain.com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.CommonMessageConversations.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.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage
import kotlinx.coroutines.flow.*
/**
* Simple factory to convert [ContentMessage] to a [CommonMessage]
*/
fun > Flow.onlyCommonMessages() = filterIsInstance>()
/**
* Shortcut for [onlyCommonMessages]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun > Flow.commonMessages() = onlyCommonMessages()
/**
* Filter the messages and checking that incoming [CommonMessage] is [PossiblySentViaBotCommonMessage] and its
* [PossiblySentViaBotCommonMessage.senderBot] is not null
*/
fun > Flow.onlySentViaBot() = mapNotNull {
if (it is PossiblySentViaBot && it.senderBot != null) {
it
} else {
null
}
}
/**
* Filter the messages and checking that incoming [CommonMessage] not is [PossiblySentViaBotCommonMessage] or its
* [PossiblySentViaBotCommonMessage.senderBot] is null
*/
fun > Flow.withoutSentViaBot() = filter {
it !is PossiblySentViaBot || it.senderBot == null
}