Opportunities out of the box¶
There are several important opportunities out of the box:
- Database access
- Config access
- Bot setup
- Json format
- Bot itself
Database access¶
You may access database in your plugin via koin in setupBotPlugin
or as parameter in setupDI
:
object YourPlugin : Plugin {
// ...
override fun Module.setupDI(
database: Database, // database
params: JsonObject
) {
// ...
}
}
It is simple Exposed database and you may use it in your tables.
Config access¶
As you may see, in the setupDI
function we also have params
parameter with source configuration json. In case
you wish to declare and work with your own config in plugin, you may use next snippet:
object YourPlugin : Plugin {
@Serializable
data class MyConfig(
val param1: String,
val param2: Int,
)
// ...
override fun Module.setupDI(
database: Database, // database
params: JsonObject
) {
single {
get<Json>().decodeFromJsonElement(MyConfig.serializer(), params) // register from root (1)
}
// OR
single {
get<Json>().decodeFromJsonElement(MyConfig.serializer(), params["yourplugin"]!!) // register from field "yourplugin" (2)
}
// ...
}
override suspend fun BehaviourContext.setupBotPlugin(
koin: Koin
) {
koin.get<MyConfig>() // getting of registered config
}
}
- In this case your config will looks like:
- In this case your config will looks like:
Bot setup¶
Out of the box you may setup several things in bot:
StatesManager<State>
(1)DefaultStatesManagerRepo<State>
(2)- Any amount of
OnStartContextsConflictResolver
(3) - Any amount of
OnUpdateContextsConflictResolver
(4) StateHandlingErrorHandler<State>
(5)
- For this use next code in
setupDI
: - For this use next code in
setupDI
: - You may declare any amount of
OnStartContextsConflictResolver
.PlaguBot
will take first non-null result of resolvers from DI and use in default states manager. To declare, use next snippet: - You may declare any amount of
OnUpdateContextsConflictResolver
.PlaguBot
will take first non-null result of resolvers from DI and use in default states manager. To declare, use next snippet: - You may declare only one
StateHandlingErrorHandler<State>
. This handler will be called each time when some state will be handled with exception and may returnnull
or new state instead old one: