diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt b/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt index 89cb216..67926e2 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/HelloPlugin.kt @@ -1,10 +1,14 @@ package dev.inmo.plagubot import dev.inmo.kslog.common.* +import dev.inmo.micro_utils.fsm.common.State +import dev.inmo.plagubot.HelloPlugin.setupBotPlugin import dev.inmo.tgbotapi.extensions.api.bot.getMe import dev.inmo.tgbotapi.extensions.api.send.reply import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand +import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUnhandledCommand import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json diff --git a/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt b/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt index 917da19..8f721bf 100644 --- a/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt +++ b/bot/src/main/kotlin/dev/inmo/plagubot/PlaguBot.kt @@ -62,7 +62,7 @@ data class PlaguBot( ) } - override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { + override suspend fun BehaviourContextWithFSM.setupBotPlugin(koin: Koin) { config.plugins.map { plugin -> launch { runCatchingSafely { @@ -113,7 +113,7 @@ data class PlaguBot( behaviourContext = this setupBotPlugin(koinApp.koin) deleteWebhook() - } + }.start() logger.i("Behaviour builder has been setup") return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext).also { logger.i("Long polling has been started") diff --git a/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt b/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt index cd493c5..83d6ad6 100644 --- a/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt +++ b/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt @@ -25,9 +25,19 @@ interface Plugin { database: Database, params: JsonObject ) {} + + /** + * Override this method in cases when you want to declare common bot behaviour. In case you wish to use FSM, you + * should override the method with receiver [BehaviourContextWithFSM] + */ suspend fun BehaviourContext.setupBotPlugin( koin: Koin ) {} + /** + * Override this method in cases when you want to declare full behaviour of the plugin. It is recommended to declare + * common logic of plugin in the [setupBotPlugin] with [BehaviourContext] receiver and use override this one + * for the FSM configuration + */ suspend fun BehaviourContextWithFSM.setupBotPlugin(koin: Koin) { (this as BehaviourContext).setupBotPlugin(koin) }