add docs in introduction plugin

This commit is contained in:
InsanusMokrassar 2022-06-18 19:51:31 +06:00
parent 529d5fb74c
commit 7bfba4ee22

View File

@ -13,19 +13,40 @@ import org.jetbrains.exposed.sql.Database
import org.koin.core.Koin import org.koin.core.Koin
import org.koin.core.module.Module import org.koin.core.module.Module
/**
* This plugin represents simple plugin which realize all necessary functionality of plugin you may need in context of simple plugins.
* In context of this plugin we will decode plugin configuration and setup reaction on `/start` command. In `introduction`
* section of config you should put field `onStartCommandMessage` which will be sent to use on `/start` command
*/
@Serializable @Serializable
class IntroductionPlugin : Plugin { class IntroductionPlugin : Plugin {
/**
* Default logger of [IntroductionPlugin] got with [logger]
*/
private val log = logger private val log = logger
/**
* Configuration class for current plugin
*
* See realization of [setupDI] to get know how this class will be deserialized from global config
*
* See realization of [setupBotPlugin] to get know how to get access to this class
*/
@Serializable @Serializable
private class Config( private class Config(
val onStartCommandMessage: String val onStartCommandMessage: String
) )
/**
* DI configuration of current plugin. Here we are decoding [Config] and put it into [Module] receiver
*/
override fun Module.setupDI(database: Database, params: JsonObject) { override fun Module.setupDI(database: Database, params: JsonObject) {
single { get<Json>().decodeFromJsonElement(Config.serializer(), params["introduction"] ?: return@single null) } single { get<Json>().decodeFromJsonElement(Config.serializer(), params["introduction"] ?: return@single null) }
} }
/**
* Final configuration of bot. Here we are getting [Config] from [koin] and configure reaction on `/start` command
*/
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) { override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
val config = koin.getOrNull<Config>() val config = koin.getOrNull<Config>()