mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-11-22 07:33:46 +00:00
initPlaguBot -> initPlaguBot: Job
This commit is contained in:
parent
22f77f8a0f
commit
9d79132b2f
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## 0.1.3
|
## 0.1.3
|
||||||
|
|
||||||
|
* `Bot`
|
||||||
|
* `initPlaguBot` now will return `Job`
|
||||||
* `Plugin`
|
* `Plugin`
|
||||||
* Plugin serializer
|
* Plugin serializer
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ import java.io.File
|
|||||||
suspend inline fun initPlaguBot(
|
suspend inline fun initPlaguBot(
|
||||||
config: Config,
|
config: Config,
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
) {
|
): Job {
|
||||||
val bot = telegramBot(config.botToken)
|
val bot = telegramBot(config.botToken)
|
||||||
|
|
||||||
val paramsMap = config.params ?.toMap() ?: emptyMap()
|
val paramsMap = config.params ?.toMap() ?: emptyMap()
|
||||||
val database = config.params ?.database ?: config.database.database
|
val database = config.params ?.database ?: config.database.database
|
||||||
bot.buildBehaviour(scope) {
|
return bot.buildBehaviour(scope) {
|
||||||
val commands = config.plugins.flatMap {
|
val commands = config.plugins.flatMap {
|
||||||
it.apply { invoke(database, paramsMap) }
|
it.apply { invoke(database, paramsMap) }
|
||||||
it.getCommands()
|
it.getCommands()
|
||||||
@ -45,6 +45,5 @@ suspend fun main(args: Array<String>) {
|
|||||||
val config = configSerialFormat.decodeFromString(Config.serializer(), file.readText())
|
val config = configSerialFormat.decodeFromString(Config.serializer(), file.readText())
|
||||||
|
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
val scope = CoroutineScope(Dispatchers.Default)
|
||||||
initPlaguBot(config, scope)
|
initPlaguBot(config, scope).join()
|
||||||
scope.coroutineContext.job.join()
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user