PlaguBot/bot/src/main/kotlin/dev/inmo/plagubot/App.kt

25 lines
795 B
Kotlin
Raw Normal View History

2020-11-08 13:23:01 +00:00
package dev.inmo.plagubot
2020-11-08 13:04:44 +00:00
2022-06-11 13:15:09 +00:00
import dev.inmo.kslog.common.*
2021-02-16 19:21:41 +00:00
import dev.inmo.plagubot.config.*
2020-11-11 17:05:21 +00:00
import kotlinx.coroutines.*
2020-11-12 05:52:09 +00:00
import kotlinx.serialization.InternalSerializationApi
2022-05-16 14:07:57 +00:00
import kotlinx.serialization.json.jsonObject
2020-11-11 17:05:21 +00:00
import java.io.File
2020-11-08 13:04:44 +00:00
2020-11-13 05:25:04 +00:00
/**
* This method by default expects one argument in [args] field: path to config
*/
@InternalSerializationApi
suspend fun main(args: Array<String>) {
2022-06-11 13:15:09 +00:00
KSLog.default = KSLog("PlaguBot")
2020-11-13 05:25:04 +00:00
val (configPath) = args
val file = File(configPath)
2022-06-11 13:15:09 +00:00
KSLog.i("Start read config from ${file.absolutePath}")
2022-05-16 14:07:57 +00:00
val json = defaultJsonFormat.parseToJsonElement(file.readText()).jsonObject
val config = defaultJsonFormat.decodeFromJsonElement(Config.serializer(), json)
2022-06-11 13:15:09 +00:00
KSLog.i("Config has been read")
2020-11-13 05:25:04 +00:00
2022-05-16 14:07:57 +00:00
PlaguBot(json, config).start().join()
2020-11-08 13:04:44 +00:00
}