From 097d82b4b461888977ca186e3584a39f233d3f4c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Mar 2025 08:59:16 +0600 Subject: [PATCH 1/5] start 24.0.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 868ada3c98..6cc1f0a184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 24.0.2 + ## 24.0.1 * `Core`: diff --git a/gradle.properties b/gradle.properties index c799a051eb..b70c3b85aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=24.0.1 +library_version=24.0.2 From 3f4018f9691c3af59fd89bd813054b4260abfbb4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Mar 2025 09:25:19 +0600 Subject: [PATCH 2/5] update KSLog part of library --- CHANGELOG.md | 3 ++ .../dev/inmo/tgbotapi/utils/DefaultKSLog.kt | 45 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc1f0a184..a8c45ca5e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 24.0.2 +* `DefaultKTgBotAPIKSLog` will drop `CancellationException`s by default +* You may configure `DefaultKTgBotAPIKSLog` in simple way with `SetDefaultKTgBotAPIKSLog` + ## 24.0.1 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/DefaultKSLog.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/DefaultKSLog.kt index 8ac4a4baa7..d781274496 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/DefaultKSLog.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/DefaultKSLog.kt @@ -2,18 +2,59 @@ package dev.inmo.tgbotapi.utils import dev.inmo.kslog.common.KSLog import dev.inmo.kslog.common.LogLevel +import dev.inmo.kslog.common.MessageFilter import dev.inmo.kslog.common.TagLogger +import dev.inmo.kslog.common.filter.filtered +import kotlinx.coroutines.CancellationException /** * Default tag for [DefaultKTgBotAPIKSLog]. You may change it and tag will be changed since the near logging */ var DefaultKTgBotAPIKSLogSystemTag: String = "KTgBot" + +private inline fun CreateDefaultKSLogger( + crossinline loggerTagGetter: () -> String, + dropCancellationExceptions: Boolean = true, + noinline additionalLoggerMapper: (KSLog.() -> KSLog)? = null +): KSLog { + val filter: MessageFilter? = if (dropCancellationExceptions) { + { ll, message, e -> + e !is CancellationException + } + } else { + null + } + return KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> + TagLogger(loggerTagGetter()).performLog(level, tag, message, throwable) + }.let { + if (filter == null) { + additionalLoggerMapper ?.invoke(it) ?: it + } else { + val base = it.filtered(filter) + additionalLoggerMapper ?.invoke(base) ?: base + } + } +} /** * Default realization of [KSLog] which will be used everywhere where there is no some custom variant of [KSLog] * * By default, uses [KSLog] factory with lambda and tag [DefaultKTgBotAPIKSLogSystemTag] (which in fact falling back to * [KSLog.default] with `KTgBot` default tag) + * + * @see SetDefaultKTgBotAPIKSLog */ -var DefaultKTgBotAPIKSLog: KSLog = KSLog { level: LogLevel, tag: String?, message: Any, throwable: Throwable? -> - TagLogger(DefaultKTgBotAPIKSLogSystemTag).performLog(level, tag, message, throwable) +var DefaultKTgBotAPIKSLog: KSLog = CreateDefaultKSLogger({ DefaultKTgBotAPIKSLogSystemTag } ) + +/** + * Setting [DefaultKTgBotAPIKSLog] with applying of [dropCancellationExceptions] and [additionalFilter] to it + * + * @param dropCancellationExceptions Will drap coroutines job [CancellationException]s + * @param additionalLoggerMapper Receives [KSLog] to allow you to use extensions like [filtered]. Returned + * [KSLog] will be used as the result [KSLog] in [DefaultKTgBotAPIKSLog] + */ +fun SetDefaultKTgBotAPIKSLog( + dropCancellationExceptions: Boolean = true, + additionalLoggerMapper: (KSLog.() -> KSLog)? = null +) { + DefaultKTgBotAPIKSLog = CreateDefaultKSLogger({ DefaultKTgBotAPIKSLogSystemTag }, dropCancellationExceptions, additionalLoggerMapper) } From 0afbe8ef2dd4c3fa70d2713b1f1e544d28a33d53 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 25 Mar 2025 18:56:59 +0600 Subject: [PATCH 3/5] update dependencies --- CHANGELOG.md | 4 ++++ gradle/libs.versions.toml | 8 ++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- tgbotapi.core/api/tgbotapi.core.api | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c45ca5e5..1b1beadfca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 24.0.2 +* `Version`: + * `Kotlin`: `2.1.10` -> `2.1.20` + * `Ktor`: `3.1.0` -> `3.1.1` + * `MicroUtils`: `0.24.7` -> `0.25.3` * `DefaultKTgBotAPIKSLog` will drop `CancellationException`s by default * You may configure `DefaultKTgBotAPIKSLog` in simple way with `SetDefaultKTgBotAPIKSLog` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b13e080c54..2f41247f5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -kotlin = "2.1.10" +kotlin = "2.1.20" kotlin-serialization = "1.8.0" kotlin-coroutines = "1.10.1" @@ -8,12 +8,12 @@ javax-activation = "1.1.1" korlibs = "5.4.0" uuid = "0.8.4" -ktor = "3.1.0" +ktor = "3.1.1" -ksp = "2.1.10-1.0.30" +ksp = "2.1.20-1.0.31" kotlin-poet = "1.18.1" -microutils = "0.24.7" +microutils = "0.25.3" kslog = "1.4.1" versions = "0.51.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c6a2952d3c..32949f9ccb 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip diff --git a/tgbotapi.core/api/tgbotapi.core.api b/tgbotapi.core/api/tgbotapi.core.api index b50774fcfb..6f2cc5147d 100644 --- a/tgbotapi.core/api/tgbotapi.core.api +++ b/tgbotapi.core/api/tgbotapi.core.api @@ -27147,6 +27147,8 @@ public final class dev/inmo/tgbotapi/utils/ByteReadChannelAllocatorDeserializati } public final class dev/inmo/tgbotapi/utils/DefaultKSLogKt { + public static final fun SetDefaultKTgBotAPIKSLog (ZLkotlin/jvm/functions/Function1;)V + public static synthetic fun SetDefaultKTgBotAPIKSLog$default (ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)V public static final fun getDefaultKTgBotAPIKSLog ()Ldev/inmo/kslog/common/KSLog; public static final fun getDefaultKTgBotAPIKSLogSystemTag ()Ljava/lang/String; public static final fun setDefaultKTgBotAPIKSLog (Ldev/inmo/kslog/common/KSLog;)V From 8a3a05ef12ce597a7fcf3ce5c1e7af02d073ed79 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 26 Mar 2025 09:45:30 +0600 Subject: [PATCH 4/5] fix of cancelling absence for subchains which become out of FSM --- .../behaviour_builder/BehaviourContextWithFSM.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt index 9f802e598a..1d94e4befe 100644 --- a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt +++ b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt @@ -144,10 +144,12 @@ class DefaultBehaviourContextWithFSM( state.context ).apply { stateInitialAction(state) - }.launchStateHandling( - state, - actualHandlersList - ) + }.run { + launchStateHandling( + state, + actualHandlersList + ) + } } override fun add(kClass: KClass, strict: Boolean, handler: BehaviourWithFSMStateHandler) { @@ -188,7 +190,7 @@ class DefaultBehaviourContextWithFSM( statesJobsMutex.withLock { runCatchingSafely { statesJobs.remove(it) ?.cancel() } } - updatesFlows.remove(it.context) + updatesFlows.remove(it.context) ?.cancel() } statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { (old, new) -> statesJobsMutex.withLock { @@ -197,7 +199,7 @@ class DefaultBehaviourContextWithFSM( statesJobs[new] = launch { statePerformer(new) }.apply { enableRemoveOnCompletion(new) } } if (old.context != new.context) { - updatesFlows.remove(old.context) + updatesFlows.remove(old.context) ?.cancel() } } From c773736fb8576c579bd691b4e2b89323115eb9ba Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 26 Mar 2025 10:12:19 +0600 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b1beadfca..608aa050e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ * `MicroUtils`: `0.24.7` -> `0.25.3` * `DefaultKTgBotAPIKSLog` will drop `CancellationException`s by default * You may configure `DefaultKTgBotAPIKSLog` in simple way with `SetDefaultKTgBotAPIKSLog` +* `BehaviourBuilder`: + * `FSM`: + * Fix chains cancelling on their ends ## 24.0.1