This commit is contained in:
InsanusMokrassar 2023-12-24 23:24:04 +06:00
parent 6c45a8c848
commit d51e2d8e7c
3 changed files with 20 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import dev.inmo.micro_utils.fsm.common.StatesManager
import dev.inmo.micro_utils.fsm.common.managers.*
import dev.inmo.micro_utils.koin.getAllDistinct
import dev.inmo.plagubot.config.*
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
@ -37,7 +38,20 @@ data class PlaguBot(
private val config: Config
) : Plugin {
@Transient
private val bot = telegramBot(config.botToken)
private val bot = telegramBot(
token = config.botToken,
apiUrl = config.botApiServer
) {
setupBotClient()
}
override fun KtorRequestsExecutorBuilder.setupBotClient() {
config.plugins.forEach {
with(it) {
setupBotClient()
}
}
}
override fun Module.setupDI(database: Database, params: JsonObject) {
single { config }

View File

@ -2,6 +2,7 @@ package dev.inmo.plagubot.config
import dev.inmo.micro_utils.common.Warning
import dev.inmo.plagubot.Plugin
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@ -12,4 +13,5 @@ data class Config(
val plugins: List<Plugin>,
@SerialName("database")
val databaseConfig: DatabaseConfig = DatabaseConfig(),
val botApiServer: String = telegramBotAPIDefaultUrl
)

View File

@ -1,6 +1,7 @@
package dev.inmo.plagubot
import dev.inmo.micro_utils.fsm.common.State
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
import kotlinx.serialization.Serializable
@ -18,6 +19,8 @@ import org.koin.core.module.Module
*/
@Serializable(PluginSerializer::class)
interface Plugin {
fun KtorRequestsExecutorBuilder.setupBotClient() {}
/**
* This method will be called when this plugin should configure di module based on the incoming params
*/