mirror of
https://github.com/InsanusMokrassar/PlaguBot.git
synced 2024-11-22 15:43:47 +00:00
add logging inside of plagubot
This commit is contained in:
parent
6b2b0b07f5
commit
8aaaa86dd4
@ -16,6 +16,8 @@ import org.koin.core.context.GlobalContext
|
|||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.scope.Scope
|
import org.koin.core.scope.Scope
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
import java.util.logging.Level
|
||||||
|
import java.util.logging.Logger
|
||||||
|
|
||||||
val Scope.plagubot: PlaguBot
|
val Scope.plagubot: PlaguBot
|
||||||
get() = get()
|
get() = get()
|
||||||
@ -25,6 +27,8 @@ data class PlaguBot(
|
|||||||
private val json: JsonObject,
|
private val json: JsonObject,
|
||||||
private val config: Config
|
private val config: Config
|
||||||
) : Plugin {
|
) : Plugin {
|
||||||
|
@Transient
|
||||||
|
private val logger = Logger.getLogger("PlaguBot")
|
||||||
@Transient
|
@Transient
|
||||||
private val bot = telegramBot(config.botToken)
|
private val bot = telegramBot(config.botToken)
|
||||||
|
|
||||||
@ -37,20 +41,28 @@ data class PlaguBot(
|
|||||||
single { this@PlaguBot }
|
single { this@PlaguBot }
|
||||||
|
|
||||||
includes(
|
includes(
|
||||||
config.plugins.map {
|
config.plugins.mapNotNull {
|
||||||
module {
|
runCatching {
|
||||||
with(it) {
|
module {
|
||||||
setupDI(database, params)
|
with(it) {
|
||||||
|
setupDI(database, params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}.onFailure { e ->
|
||||||
|
logger.log(Level.WARNING, "Unable to load DI part of $it", e)
|
||||||
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||||
config.plugins.forEach {
|
config.plugins.forEach {
|
||||||
with(it) {
|
runCatching {
|
||||||
setupBotPlugin(koin)
|
with(it) {
|
||||||
|
setupBotPlugin(koin)
|
||||||
|
}
|
||||||
|
}.onFailure { e ->
|
||||||
|
logger.log(Level.WARNING, "Unable to load bot part of $it", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,19 +73,26 @@ data class PlaguBot(
|
|||||||
suspend fun start(
|
suspend fun start(
|
||||||
scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
|
scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
|
||||||
): Job {
|
): Job {
|
||||||
|
logger.info("Start initialization")
|
||||||
val koinApp = KoinApplication.init()
|
val koinApp = KoinApplication.init()
|
||||||
koinApp.modules(
|
koinApp.modules(
|
||||||
module {
|
module {
|
||||||
setupDI(config.databaseConfig.database, json)
|
setupDI(config.databaseConfig.database, json)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
logger.info("Modules loaded")
|
||||||
GlobalContext.startKoin(koinApp)
|
GlobalContext.startKoin(koinApp)
|
||||||
|
logger.info("Koin started")
|
||||||
lateinit var behaviourContext: BehaviourContext
|
lateinit var behaviourContext: BehaviourContext
|
||||||
bot.buildBehaviour(scope = scope) {
|
bot.buildBehaviour(scope = scope) {
|
||||||
|
logger.info("Start setup of bot part")
|
||||||
behaviourContext = this
|
behaviourContext = this
|
||||||
setupBotPlugin(koinApp.koin)
|
setupBotPlugin(koinApp.koin)
|
||||||
deleteWebhook()
|
deleteWebhook()
|
||||||
}
|
}
|
||||||
return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext)
|
logger.info("Behaviour builder has been setup")
|
||||||
|
return bot.startGettingOfUpdatesByLongPolling(scope = behaviourContext, updatesFilter = behaviourContext).also {
|
||||||
|
logger.info("Long polling has been started")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user