mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-01-02 22:10:04 +00:00
add CombinedSubcontextInitialAction
This commit is contained in:
parent
a87560bc40
commit
402e695f99
@ -82,6 +82,27 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourConte
|
|||||||
public static final fun stop (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;)V
|
public static final fun stop (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;)V
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction {
|
||||||
|
public fun <init> (Ljava/util/List;Ldev/inmo/kslog/common/KSLog;)V
|
||||||
|
public synthetic fun <init> (Ljava/util/List;Ldev/inmo/kslog/common/KSLog;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||||
|
public final fun getSubactions ()Ljava/util/List;
|
||||||
|
public final fun getSubcontextInitialAction ()Lkotlin/jvm/functions/Function3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract interface class dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction$SubAction {
|
||||||
|
public abstract fun invoke (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/types/update/abstracts/Update;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction$SubAction$Callback : dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialAction$SubAction {
|
||||||
|
public fun <init> (Lkotlin/jvm/functions/Function3;)V
|
||||||
|
public fun invoke (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/types/update/abstracts/Update;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/CombinedSubcontextInitialActionKt {
|
||||||
|
public static final fun buildSubcontextInitialAction (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3;
|
||||||
|
public static final fun buildSubcontextInitialActionWithSubActions (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function3;
|
||||||
|
}
|
||||||
|
|
||||||
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext : dev/inmo/tgbotapi/updateshandlers/AbstractFlowsUpdatesFilter, dev/inmo/tgbotapi/bot/RequestsExecutor, dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext, kotlinx/coroutines/CoroutineScope {
|
public final class dev/inmo/tgbotapi/extensions/behaviour_builder/DefaultBehaviourContext : dev/inmo/tgbotapi/updateshandlers/AbstractFlowsUpdatesFilter, dev/inmo/tgbotapi/bot/RequestsExecutor, dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext, kotlinx/coroutines/CoroutineScope {
|
||||||
public fun <init> (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;)V
|
public fun <init> (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;)V
|
||||||
public synthetic fun <init> (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
public synthetic fun <init> (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Lkotlinx/coroutines/CoroutineScope;ILkotlinx/coroutines/channels/BufferOverflow;Lkotlinx/coroutines/flow/Flow;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlin/jvm/functions/Function3;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.behaviour_builder
|
||||||
|
|
||||||
|
import dev.inmo.kslog.common.KSLog
|
||||||
|
import dev.inmo.kslog.common.error
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
|
class CombinedSubcontextInitialAction(
|
||||||
|
val subactions: List<SubAction>,
|
||||||
|
private val logger: KSLog = KSLog("CombinedSubcontextInitialAction_${subactions.size}")
|
||||||
|
) {
|
||||||
|
fun interface SubAction {
|
||||||
|
suspend operator fun BehaviourContext.invoke(update: Update)
|
||||||
|
|
||||||
|
class Callback(private val action: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>) : SubAction {
|
||||||
|
override suspend fun BehaviourContext.invoke(update: Update) {
|
||||||
|
action(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val subcontextInitialAction: CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> = { update ->
|
||||||
|
subactions.forEach { subaction ->
|
||||||
|
with(subaction) {
|
||||||
|
runCatching {
|
||||||
|
invoke(update)
|
||||||
|
}.onFailure {
|
||||||
|
logger.error("Unable to execute $subaction for update $update", it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun buildSubcontextInitialActionWithSubActions(
|
||||||
|
block: MutableList<CombinedSubcontextInitialAction.SubAction>.() -> Unit
|
||||||
|
): CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> {
|
||||||
|
val list = mutableListOf<CombinedSubcontextInitialAction.SubAction>()
|
||||||
|
list.block()
|
||||||
|
return CombinedSubcontextInitialAction(
|
||||||
|
list.toList()
|
||||||
|
).subcontextInitialAction
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun buildSubcontextInitialAction(
|
||||||
|
block: MutableList<CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>>.() -> Unit
|
||||||
|
): CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update> {
|
||||||
|
val list = mutableListOf<CustomBehaviourContextAndTypeReceiver<BehaviourContext, Unit, Update>>()
|
||||||
|
list.block()
|
||||||
|
return CombinedSubcontextInitialAction(
|
||||||
|
list.map {
|
||||||
|
CombinedSubcontextInitialAction.SubAction.Callback(it)
|
||||||
|
}
|
||||||
|
).subcontextInitialAction
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user