PlaguBot/plugin/src/main/kotlin/dev/inmo/plagubot/Plugin.kt

48 lines
1.8 KiB
Kotlin
Raw Normal View History

2020-11-08 13:23:01 +00:00
package dev.inmo.plagubot
2022-08-13 14:09:21 +00:00
import dev.inmo.micro_utils.fsm.common.State
2023-12-24 17:24:04 +00:00
import dev.inmo.tgbotapi.bot.ktor.KtorRequestsExecutorBuilder
2021-01-10 09:21:31 +00:00
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
2022-08-13 14:09:21 +00:00
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextWithFSM
import kotlinx.serialization.Serializable
2022-05-13 07:04:49 +00:00
import kotlinx.serialization.json.JsonObject
2020-11-11 17:05:21 +00:00
import org.jetbrains.exposed.sql.Database
2022-05-16 14:07:57 +00:00
import org.koin.core.Koin
2022-05-16 17:58:16 +00:00
import org.koin.core.module.Module
2020-11-11 17:05:21 +00:00
2020-11-12 06:16:43 +00:00
/**
2022-05-13 07:04:49 +00:00
* **ANY REALIZATION OF [Plugin] MUST HAVE CONSTRUCTOR WITH ABSENCE OF INCOMING PARAMETERS**
*
2020-11-12 06:16:43 +00:00
* Use this interface for your bot. It is possible to use [kotlinx.serialization.SerialName] annotations on your plugins
* to set up short name for your plugin. Besides, simple name of your class will be used as key for deserialization
* too.
*/
@Serializable(PluginSerializer::class)
2022-05-16 17:58:16 +00:00
interface Plugin {
2023-12-24 17:24:04 +00:00
fun KtorRequestsExecutorBuilder.setupBotClient() {}
2021-01-10 09:21:31 +00:00
/**
2022-05-16 17:58:16 +00:00
* This method will be called when this plugin should configure di module based on the incoming params
2021-01-10 09:21:31 +00:00
*/
2022-05-16 17:58:16 +00:00
fun Module.setupDI(
2022-05-13 07:04:49 +00:00
database: Database,
params: JsonObject
2022-05-16 18:03:27 +00:00
) {}
2022-08-13 14:30:10 +00:00
/**
* 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]
*/
2022-05-16 17:58:16 +00:00
suspend fun BehaviourContext.setupBotPlugin(
koin: Koin
2022-05-16 18:03:27 +00:00
) {}
2022-08-13 14:30:10 +00:00
/**
* 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
*/
2022-08-13 14:09:21 +00:00
suspend fun BehaviourContextWithFSM<State>.setupBotPlugin(koin: Koin) {
(this as BehaviourContext).setupBotPlugin(koin)
}
2020-11-11 17:05:21 +00:00
}