mirror of
				https://github.com/InsanusMokrassar/PlaguBot.git
				synced 2025-10-30 19:50:24 +00:00 
			
		
		
		
	| @@ -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.fsm.common.managers.* | ||||||
| import dev.inmo.micro_utils.koin.getAllDistinct | import dev.inmo.micro_utils.koin.getAllDistinct | ||||||
| import dev.inmo.plagubot.config.* | import dev.inmo.plagubot.config.* | ||||||
|  | import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder | ||||||
| import dev.inmo.tgbotapi.bot.ktor.telegramBot | import dev.inmo.tgbotapi.bot.ktor.telegramBot | ||||||
| import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook | import dev.inmo.tgbotapi.extensions.api.webhook.deleteWebhook | ||||||
| import dev.inmo.tgbotapi.extensions.behaviour_builder.* | import dev.inmo.tgbotapi.extensions.behaviour_builder.* | ||||||
| @@ -37,7 +38,20 @@ data class PlaguBot( | |||||||
|     private val config: Config |     private val config: Config | ||||||
| ) : Plugin { | ) : Plugin { | ||||||
|     @Transient |     @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) { |     override fun Module.setupDI(database: Database, params: JsonObject) { | ||||||
|         single { config } |         single { config } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ package dev.inmo.plagubot.config | |||||||
|  |  | ||||||
| import dev.inmo.micro_utils.common.Warning | import dev.inmo.micro_utils.common.Warning | ||||||
| import dev.inmo.plagubot.Plugin | import dev.inmo.plagubot.Plugin | ||||||
|  | import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl | ||||||
| import kotlinx.serialization.SerialName | import kotlinx.serialization.SerialName | ||||||
| import kotlinx.serialization.Serializable | import kotlinx.serialization.Serializable | ||||||
|  |  | ||||||
| @@ -12,4 +13,5 @@ data class Config( | |||||||
|     val plugins: List<Plugin>, |     val plugins: List<Plugin>, | ||||||
|     @SerialName("database") |     @SerialName("database") | ||||||
|     val databaseConfig: DatabaseConfig = DatabaseConfig(), |     val databaseConfig: DatabaseConfig = DatabaseConfig(), | ||||||
|  |     val botApiServer: String = telegramBotAPIDefaultUrl | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package dev.inmo.plagubot | package dev.inmo.plagubot | ||||||
|  |  | ||||||
| import dev.inmo.micro_utils.fsm.common.State | 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.BehaviourContext | ||||||
| import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM | import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM | ||||||
| import kotlinx.serialization.Serializable | import kotlinx.serialization.Serializable | ||||||
| @@ -18,6 +19,8 @@ import org.koin.core.module.Module | |||||||
|  */ |  */ | ||||||
| @Serializable(PluginSerializer::class) | @Serializable(PluginSerializer::class) | ||||||
| interface Plugin { | interface Plugin { | ||||||
|  |     fun KtorRequestsExecutorBuilder.setupBotClient() {} | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This method will be called when this plugin should configure di module based on the incoming params |      * This method will be called when this plugin should configure di module based on the incoming params | ||||||
|      */ |      */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user