update dependencies and add logging

This commit is contained in:
2022-06-11 19:15:09 +06:00
parent 343c26a7f1
commit f9f56f6afb
7 changed files with 28 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ dependencies {
api libs.tgbotapi
api libs.microutils.repos.exposed
api libs.kslog
api libs.sqlite

View File

@@ -1,5 +1,6 @@
package dev.inmo.plagubot
import dev.inmo.kslog.common.*
import dev.inmo.plagubot.config.*
import kotlinx.coroutines.*
import kotlinx.serialization.InternalSerializationApi
@@ -11,10 +12,13 @@ import java.io.File
*/
@InternalSerializationApi
suspend fun main(args: Array<String>) {
KSLog.default = KSLog("PlaguBot")
val (configPath) = args
val file = File(configPath)
KSLog.i("Start read config from ${file.absolutePath}")
val json = defaultJsonFormat.parseToJsonElement(file.readText()).jsonObject
val config = defaultJsonFormat.decodeFromJsonElement(Config.serializer(), json)
KSLog.i("Config has been read")
PlaguBot(json, config).start().join()
}

View File

@@ -1,5 +1,7 @@
package dev.inmo.plagubot
import dev.inmo.kslog.common.d
import dev.inmo.kslog.common.logger
import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
@@ -30,8 +32,8 @@ class HelloPlugin : Plugin {
}
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
println(koin.get<HelloPluginConfig>().print)
println(getMe())
logger.d(koin.get<HelloPluginConfig>().print)
logger.d(getMe().toString())
onCommand("hello_world") {
reply(it, "Hello :)")
}

View File

@@ -1,5 +1,6 @@
package dev.inmo.plagubot
import dev.inmo.kslog.common.*
import dev.inmo.micro_utils.coroutines.runCatchingSafely
import dev.inmo.plagubot.config.*
import dev.inmo.tgbotapi.bot.ktor.telegramBot
@@ -28,8 +29,6 @@ data class PlaguBot(
private val json: JsonObject,
private val config: Config
) : Plugin {
@Transient
private val logger = Logger.getLogger("PlaguBot")
@Transient
private val bot = telegramBot(config.botToken)
@@ -50,7 +49,7 @@ data class PlaguBot(
}
}
}.onFailure { e ->
logger.log(Level.WARNING, "Unable to load DI part of $it", e)
logger.log(LogLevel.WARNING, "Unable to load DI part of $it", e)
}.getOrNull()
}
)
@@ -65,7 +64,7 @@ data class PlaguBot(
setupBotPlugin(koin)
}
}.onFailure { e ->
logger.log(Level.WARNING, "Unable to load bot part of $it", e)
logger.log(LogLevel.WARNING, "Unable to load bot part of $it", e)
}.onSuccess {
logger.info("Complete loading of $it")
}