fixes/fill of docs

This commit is contained in:
InsanusMokrassar 2022-08-13 20:30:10 +06:00
parent 751e9aa66c
commit 7dad3581f1
3 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -62,7 +62,7 @@ data class PlaguBot(
)
}
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
override suspend fun BehaviourContextWithFSM<State>.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")

View File

@ -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<State>.setupBotPlugin(koin: Koin) {
(this as BehaviourContext).setupBotPlugin(koin)
}