mirror of
https://github.com/InsanusMokrassar/TelegramBotTutorial.git
synced 2024-12-22 06:07:11 +00:00
add docs in introduction plugin
This commit is contained in:
parent
529d5fb74c
commit
7bfba4ee22
@ -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>()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user