package com.github.insanusmokrassar.TelegramBotAPI.updateshandlers import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import kotlinx.coroutines.channels.BroadcastChannel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.asFlow @Suppress("EXPERIMENTAL_API_USAGE") private fun BroadcastChannel.createUpdateReceiver(): UpdateReceiver = ::send @Suppress("EXPERIMENTAL_API_USAGE", "unused") class FlowsUpdatesFilter( broadcastChannelsSize: Int = 64 ): UpdatesFilter { private val messageChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val messageMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val editedMessageChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val editedMessageMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val channelPostChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val channelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val editedChannelPostChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val editedChannelPostMediaGroupChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val chosenInlineResultChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val inlineQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val callbackQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val shippingQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val preCheckoutQueryChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val pollChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val pollAnswerChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) private val unknownUpdateChannel: BroadcastChannel = BroadcastChannel(broadcastChannelsSize) override val allowedUpdates: List get() = filter.allowedUpdates override val asUpdateReceiver: UpdateReceiver get() = filter.asUpdateReceiver val filter = SimpleUpdatesFilter( messageChannel.createUpdateReceiver(), messageMediaGroupChannel.createUpdateReceiver(), editedMessageChannel.createUpdateReceiver(), editedMessageMediaGroupChannel.createUpdateReceiver(), channelPostChannel.createUpdateReceiver(), channelPostMediaGroupChannel.createUpdateReceiver(), editedChannelPostChannel.createUpdateReceiver(), editedChannelPostMediaGroupChannel.createUpdateReceiver(), chosenInlineResultChannel.createUpdateReceiver(), inlineQueryChannel.createUpdateReceiver(), callbackQueryChannel.createUpdateReceiver(), shippingQueryChannel.createUpdateReceiver(), preCheckoutQueryChannel.createUpdateReceiver(), pollChannel.createUpdateReceiver(), pollAnswerChannel.createUpdateReceiver(), unknownUpdateChannel.createUpdateReceiver() ) val messageFlow: Flow = messageChannel.asFlow() val messageMediaGroupFlow: Flow = messageMediaGroupChannel.asFlow() val editedMessageFlow: Flow = editedMessageChannel.asFlow() val editedMessageMediaGroupFlow: Flow = editedMessageMediaGroupChannel.asFlow() val channelPostFlow: Flow = channelPostChannel.asFlow() val channelPostMediaGroupFlow: Flow = channelPostMediaGroupChannel.asFlow() val editedChannelPostFlow: Flow = editedChannelPostChannel.asFlow() val editedChannelPostMediaGroupFlow: Flow = editedChannelPostMediaGroupChannel.asFlow() val chosenInlineResultFlow: Flow = chosenInlineResultChannel.asFlow() val inlineQueryFlow: Flow = inlineQueryChannel.asFlow() val callbackQueryFlow: Flow = callbackQueryChannel.asFlow() val shippingQueryFlow: Flow = shippingQueryChannel.asFlow() val preCheckoutQueryFlow: Flow = preCheckoutQueryChannel.asFlow() val pollFlow: Flow = pollChannel.asFlow() val pollAnswerFlow: Flow = pollAnswerChannel.asFlow() val unknownUpdateTypeFlow: Flow = unknownUpdateChannel.asFlow() }