mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
several RiskFeature updates
This commit is contained in:
parent
0320da7614
commit
10eb15e172
@ -18,6 +18,7 @@ package dev.inmo.tgbotapi.utils
|
||||
)
|
||||
annotation class PreviewFeature
|
||||
|
||||
const val lowLevelRiskFeatureMessage = "This method is low-level and not recommended to direct use"
|
||||
@RequiresOptIn(
|
||||
"This feature can work unstable and may have some restrictions in Telegram System",
|
||||
RequiresOptIn.Level.WARNING
|
||||
|
@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
@ -26,7 +27,7 @@ typealias NullableRequestBuilder<T> = suspend (Update) -> Request<T>?
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
@RiskFeature("This method is not very comfortable to use and too low-level. It is recommended to use methods which already included into library")
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
suspend fun <T> FlowsUpdatesFilter.expectFlow(
|
||||
bot: TelegramBot,
|
||||
initRequest: Request<*>? = null,
|
||||
@ -92,7 +93,7 @@ suspend fun <T> BehaviourContext.expectFlow(
|
||||
* as is, but when it returns null, then will be called [cancelTrigger] (if it will return true - [cancelRequestFactory]
|
||||
* will be called too), [errorFactory] and then will be returned null
|
||||
*/
|
||||
@RiskFeature("This method is not very comfortable to use and too low-level. It is recommended to use methods which already included into library")
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
suspend fun <T> FlowsUpdatesFilter.expectOne(
|
||||
bot: TelegramBot,
|
||||
initRequest: Request<*>? = null,
|
||||
|
@ -12,9 +12,12 @@ import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
inline fun <reified T : MessageContent> filterForContentMessage(): suspend (ContentMessage<*>) -> ContentMessage<T>? = {
|
||||
if (it.content is T) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@ -25,9 +28,11 @@ inline fun <reified T : MessageContent> filterForContentMessage(): suspend (Cont
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
inline fun <reified T: MessageContent> Flow<BaseSentMessageUpdate>.filterContentMessages(
|
||||
): Flow<ContentMessage<T>> = asContentMessagesFlow().mapNotNull(filterForContentMessage())
|
||||
|
||||
@RiskFeature("This method is low-level")
|
||||
inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMediaGroupMessages(
|
||||
): Flow<List<CommonMessage<T>>> = map {
|
||||
it.data.mapNotNull { message ->
|
||||
@ -46,6 +51,7 @@ inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMedi
|
||||
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
||||
scopeToIncludeChannels: CoroutineScope? = null
|
||||
): Flow<ContentMessage<T>> {
|
||||
@ -64,6 +70,7 @@ inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
||||
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||
inline fun <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMessages(
|
||||
scopeToIncludeChannels: CoroutineScope? = null
|
||||
): Flow<List<CommonMessage<T>>> {
|
||||
|
Loading…
Reference in New Issue
Block a user