mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-05 16:19:26 +00:00
add ChatEventsConversations and refill README of telegramboapi-extensions-utils
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
fun <T : ChatEventMessage> Flow<ChatEventMessage>.divideBySource(contentType: KClass<T>) = mapNotNull {
|
||||
if (contentType.isInstance(it)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
it as T
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun Flow<ChatEventMessage>.channelEvents() = divideBySource(ChannelEventMessage::class)
|
||||
fun Flow<ChatEventMessage>.groupEvents() = divideBySource(GroupEventMessage::class)
|
||||
fun Flow<ChatEventMessage>.supergroupEvents() = divideBySource(SupergroupEventMessage::class)
|
Reference in New Issue
Block a user