mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
Flow<BaseSentMessageUpdate> extensions
This commit is contained in:
parent
2d15e13ae6
commit
6f650f6d6c
20
CHANGELOG.md
20
CHANGELOG.md
@ -51,6 +51,26 @@
|
|||||||
|
|
||||||
### 0.27.11
|
### 0.27.11
|
||||||
|
|
||||||
|
* `TelegramBotAPI-extensions-utils`:
|
||||||
|
* A lot of extensions like `Flow<BaseSentMessageUpdate>#textMessages` were added:
|
||||||
|
* `Flow<BaseSentMessageUpdate>#animationMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#audioMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#contactMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#diceMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#documentMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#gameMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#invoiceMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#locationMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#photoMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#imageMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#pollMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#stickerMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#textMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#venueMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#videoMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#videoNoteMessages`
|
||||||
|
* `Flow<BaseSentMessageUpdate>#voiceMessages`
|
||||||
|
|
||||||
### 0.27.10
|
### 0.27.10
|
||||||
|
|
||||||
* `TelegramBotAPI-extensions-api`:
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
@ -3,10 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.shortcuts
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.aggregateFlows
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.aggregateFlows
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.asContentMessagesFlow
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.updates.asContentMessagesFlow
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.*
|
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.abstracts.MessageContent
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.InvoiceContent
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseSentMessageUpdate
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
import com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.FlowsUpdatesFilter
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
@ -19,6 +21,10 @@ inline fun <reified T : MessageContent> filterForContentMessage(): suspend (Cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContentMessages(
|
||||||
|
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
||||||
* In this case will be created new channel which will agregate messages from [FlowsUpdatesFilter.messageFlow] and
|
* In this case will be created new channel which will agregate messages from [FlowsUpdatesFilter.messageFlow] and
|
||||||
@ -28,48 +34,57 @@ inline fun <reified T : MessageContent> filterForContentMessage(): suspend (Cont
|
|||||||
inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
): Flow<ContentMessage<T>> {
|
): Flow<ContentMessage<T>> {
|
||||||
val filter = filterForContentMessage<T>()
|
return (scopeToIncludeChannels ?.let { scope ->
|
||||||
return scopeToIncludeChannels ?.let { scope ->
|
|
||||||
aggregateFlows(
|
aggregateFlows(
|
||||||
scope,
|
scope,
|
||||||
messageFlow.asContentMessagesFlow().mapNotNull(filter),
|
messageFlow,
|
||||||
channelPostFlow.asContentMessagesFlow().mapNotNull(filter)
|
channelPostFlow
|
||||||
)
|
)
|
||||||
} ?: messageFlow.asContentMessagesFlow().mapNotNull(filter)
|
} ?: messageFlow).filterContentMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.animationMessages() = filterContentMessages<AnimationContent>()
|
||||||
fun FlowsUpdatesFilter.animationMessages(
|
fun FlowsUpdatesFilter.animationMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<AnimationContent>(scopeToIncludeChannels)
|
) = filterContentMessages<AnimationContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.audioMessages() = filterContentMessages<AudioContent>()
|
||||||
fun FlowsUpdatesFilter.audioMessages(
|
fun FlowsUpdatesFilter.audioMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<AudioContent>(scopeToIncludeChannels)
|
) = filterContentMessages<AudioContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.contactMessages() = filterContentMessages<ContactContent>()
|
||||||
fun FlowsUpdatesFilter.contactMessages(
|
fun FlowsUpdatesFilter.contactMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<ContactContent>(scopeToIncludeChannels)
|
) = filterContentMessages<ContactContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.diceMessages() = filterContentMessages<DiceContent>()
|
||||||
fun FlowsUpdatesFilter.diceMessages(
|
fun FlowsUpdatesFilter.diceMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<DiceContent>(scopeToIncludeChannels)
|
) = filterContentMessages<DiceContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.documentMessages() = filterContentMessages<DocumentContent>()
|
||||||
fun FlowsUpdatesFilter.documentMessages(
|
fun FlowsUpdatesFilter.documentMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<DocumentContent>(scopeToIncludeChannels)
|
) = filterContentMessages<DocumentContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.gameMessages() = filterContentMessages<GameContent>()
|
||||||
fun FlowsUpdatesFilter.gameMessages(
|
fun FlowsUpdatesFilter.gameMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<GameContent>(scopeToIncludeChannels)
|
) = filterContentMessages<GameContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.invoiceMessages() = filterContentMessages<InvoiceContent>()
|
||||||
fun FlowsUpdatesFilter.invoiceMessages(
|
fun FlowsUpdatesFilter.invoiceMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<InvoiceContent>(scopeToIncludeChannels)
|
) = filterContentMessages<InvoiceContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.locationMessages() = filterContentMessages<LocationContent>()
|
||||||
fun FlowsUpdatesFilter.locationMessages(
|
fun FlowsUpdatesFilter.locationMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<LocationContent>(scopeToIncludeChannels)
|
) = filterContentMessages<LocationContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.photoMessages() = filterContentMessages<PhotoContent>()
|
||||||
|
fun Flow<BaseSentMessageUpdate>.imageMessages() = photoMessages()
|
||||||
fun FlowsUpdatesFilter.photoMessages(
|
fun FlowsUpdatesFilter.photoMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<PhotoContent>(scopeToIncludeChannels)
|
) = filterContentMessages<PhotoContent>(scopeToIncludeChannels)
|
||||||
@ -81,30 +96,37 @@ inline fun FlowsUpdatesFilter.imageMessages(
|
|||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = photoMessages(scopeToIncludeChannels)
|
) = photoMessages(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.pollMessages() = filterContentMessages<PollContent>()
|
||||||
fun FlowsUpdatesFilter.pollMessages(
|
fun FlowsUpdatesFilter.pollMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<PollContent>(scopeToIncludeChannels)
|
) = filterContentMessages<PollContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.stickerMessages() = filterContentMessages<StickerContent>()
|
||||||
fun FlowsUpdatesFilter.stickerMessages(
|
fun FlowsUpdatesFilter.stickerMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<StickerContent>(scopeToIncludeChannels)
|
) = filterContentMessages<StickerContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.textMessages() = filterContentMessages<TextContent>()
|
||||||
fun FlowsUpdatesFilter.textMessages(
|
fun FlowsUpdatesFilter.textMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<TextContent>(scopeToIncludeChannels)
|
) = filterContentMessages<TextContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.venueMessages() = filterContentMessages<VenueContent>()
|
||||||
fun FlowsUpdatesFilter.venueMessages(
|
fun FlowsUpdatesFilter.venueMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VenueContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VenueContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.videoMessages() = filterContentMessages<VideoContent>()
|
||||||
fun FlowsUpdatesFilter.videoMessages(
|
fun FlowsUpdatesFilter.videoMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VideoContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VideoContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.videoNoteMessages() = filterContentMessages<VideoNoteContent>()
|
||||||
fun FlowsUpdatesFilter.videoNoteMessages(
|
fun FlowsUpdatesFilter.videoNoteMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VideoNoteContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VideoNoteContent>(scopeToIncludeChannels)
|
||||||
|
|
||||||
|
fun Flow<BaseSentMessageUpdate>.voiceMessages() = filterContentMessages<VoiceContent>()
|
||||||
fun FlowsUpdatesFilter.voiceMessages(
|
fun FlowsUpdatesFilter.voiceMessages(
|
||||||
scopeToIncludeChannels: CoroutineScope? = null
|
scopeToIncludeChannels: CoroutineScope? = null
|
||||||
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
|
) = filterContentMessages<VoiceContent>(scopeToIncludeChannels)
|
||||||
|
Loading…
Reference in New Issue
Block a user