mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-04-07 18:42:29 +00:00
complete support of ManagedBotCreated and ManagedBotUpdated, add getManagedBotToken and replaceManagedBotToken
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.utils.managedBotUpdateOrNull
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.managed_bots.ManagedBotUpdated
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
fun BehaviourContext.waitManagedBotUpdated(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
): Flow<ManagedBotUpdated> = expectFlow(
|
||||
initRequest,
|
||||
errorFactory
|
||||
) {
|
||||
(it.managedBotUpdateOrNull() ?.data).let(::listOfNotNull)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sourceUser
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
||||
import dev.inmo.tgbotapi.types.chat.ChatJoinRequest
|
||||
import dev.inmo.tgbotapi.types.managed_bots.ManagedBotUpdated
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
@@ -60,6 +61,14 @@ val InlineQueryFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, Inline
|
||||
it.id == query.user.id
|
||||
} != false
|
||||
}
|
||||
/**
|
||||
* Allow only updates from the same user as base [ManagedBotUpdated.user]
|
||||
*/
|
||||
val ManagedBotUpdatedFilterByUser: BehaviourContextAndTwoTypesReceiver<Boolean, ManagedBotUpdated, Update> = { managedBotUpdated, update ->
|
||||
update.sourceUser() ?.let {
|
||||
it.id == managedBotUpdated.user.id
|
||||
} != false
|
||||
}
|
||||
/**
|
||||
* Allow only events from the same chat as base [ChatMemberUpdated]
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTwoTypesReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTypeReceiver
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByUserManagedBotUpdatedMarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||
import dev.inmo.tgbotapi.extensions.utils.managedBotUpdateOrNull
|
||||
import dev.inmo.tgbotapi.types.managed_bots.ManagedBotUpdated
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] **Pass null to handle requests fully parallel**. Will be used to identify different "stream".
|
||||
* [scenarioReceiver] will be called synchronously in one "stream". Output of [markerFactory] will be used as a key for
|
||||
* "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
fun <BC : BehaviourContext> BC.onManagedBotUpdate(
|
||||
initialFilter: SimpleFilter<ManagedBotUpdated>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ManagedBotUpdated, Update>? = null,
|
||||
markerFactory: MarkerFactory<in ManagedBotUpdated, Any>? = ByUserManagedBotUpdatedMarkerFactory,
|
||||
additionalSubcontextInitialAction: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, Update, ManagedBotUpdated>? = null,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ManagedBotUpdated>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, additionalSubcontextInitialAction, scenarioReceiver) {
|
||||
(it.managedBotUpdateOrNull() ?.data) ?.let(::listOfNotNull)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories
|
||||
|
||||
import dev.inmo.tgbotapi.types.managed_bots.ManagedBotUpdated
|
||||
|
||||
object ByUserManagedBotUpdatedMarkerFactory : MarkerFactory<ManagedBotUpdated, Any> {
|
||||
override suspend fun invoke(data: ManagedBotUpdated) = data.user
|
||||
}
|
||||
Reference in New Issue
Block a user