From 06459ebc0a77ceef4f27d874bf2a73f9b789dd90 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Jul 2024 21:14:53 +0600 Subject: [PATCH] improve boosts info bot --- BoostsInfoBot/src/main/kotlin/BoostsInfo.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt b/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt index 520603e..6ab5ce5 100644 --- a/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt +++ b/BoostsInfoBot/src/main/kotlin/BoostsInfo.kt @@ -52,12 +52,19 @@ suspend fun main(args: Array) { } onChatShared(initialFilter = { it.chatEvent.requestId == requestChatId }) { - val boosts = getUserChatBoosts(it.chatEvent.chatId, it.chat.id) - reply( - it - ) { - boosts.boosts.forEach { - regular("Boost added: ${DateFormat.FORMAT1.format(it.addDate.asDate)}; Boost expire: ${DateFormat.FORMAT1.format(it.expirationDate.asDate)}; Unformatted: $it") + "\n" + val boostsInfoContrainer = runCatching { + getUserChatBoosts(it.chatEvent.chatId, it.chat.id) + }.getOrNull() + + reply(it) { + when { + boostsInfoContrainer == null -> +"Unable to take info about boosts in shared chat" + boostsInfoContrainer.boosts.isEmpty() -> +"There is no any boosts in passed chat" + else -> { + boostsInfoContrainer.boosts.forEach { + regular("Boost added: ${DateFormat.FORMAT1.format(it.addDate.asDate)}; Boost expire: ${DateFormat.FORMAT1.format(it.expirationDate.asDate)}; Unformatted: $it") + "\n" + } + } } } }