mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-12-04 05:10:06 +00:00
fixes/fill of docs
This commit is contained in:
parent
751e9aa66c
commit
7dad3581f1
@ -1,10 +1,14 @@
|
|||||||
package dev.inmo.plagubot
|
package dev.inmo.plagubot
|
||||||
|
|
||||||
import dev.inmo.kslog.common.*
|
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.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
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.onCommand
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUnhandledCommand
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
@ -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 ->
|
config.plugins.map { plugin ->
|
||||||
launch {
|
launch {
|
||||||
runCatchingSafely {
|
runCatchingSafely {
|
||||||
@ -113,7 +113,7 @@ data class PlaguBot(
|
|||||||
behaviourContext = this
|
behaviourContext = this
|
||||||
setupBotPlugin(koinApp.koin)
|
setupBotPlugin(koinApp.koin)
|
||||||
deleteWebhook()
|
deleteWebhook()
|
||||||
}
|
}.start()
|
||||||
logger.i("Behaviour builder has been setup")
|
logger.i("Behaviour builder has been setup")
|
||||||
return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext).also {
|
return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext).also {
|
||||||
logger.i("Long polling has been started")
|
logger.i("Long polling has been started")
|
||||||
|
@ -25,9 +25,19 @@ interface Plugin {
|
|||||||
database: Database,
|
database: Database,
|
||||||
params: JsonObject
|
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(
|
suspend fun BehaviourContext.setupBotPlugin(
|
||||||
koin: Koin
|
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) {
|
suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
|
||||||
(this as BehaviourContext).setupBotPlugin(koin)
|
(this as BehaviourContext).setupBotPlugin(koin)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user