mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-27 17:55:52 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49c2836e62 | |||
| f7476188eb | |||
| 2ba447b126 | |||
| 3bd4fab3fe |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,6 +9,7 @@ settings.xml
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
bin/
|
||||
|
||||
local.properties
|
||||
kotlin-js-store/
|
||||
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,6 +1,19 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 26.2.0
|
||||
## 27.0.0
|
||||
|
||||
**THIS UPDATE MAY CONTAIN BREAKING CHANGES. IN CASE OF ANY MIGRATION PROBLEMS FEEL FREE TO ASK IN [OUR CHAT](https://t.me/ktgbotapi_chat)**
|
||||
|
||||
* `Version`:
|
||||
* `Kotlin`: `2.1.20` -> `2.2.0`
|
||||
* `Serialization`: `1.8.1` -> `1.9.0`
|
||||
* `Ktor`: `3.1.3` -> `3.2.2`
|
||||
* `MicroUtils`: `0.25.7` -> `0.26.1`
|
||||
* `KSLog`: `1.4.1` -> `1.5.0`
|
||||
* `Common`:
|
||||
* In most `data` classes with non-public constructors has been added `ConsistentCopyVisibility` annotation, preventing
|
||||
public nature in difference with constructor
|
||||
* Absence of several API methods for requests has been fixed
|
||||
|
||||
## 26.1.0
|
||||
|
||||
|
||||
@@ -9,4 +9,4 @@ kotlin.incremental.js=true
|
||||
ksp.useKSP2=false
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=26.2.0
|
||||
library_version=27.0.0
|
||||
|
||||
@@ -8,12 +8,12 @@ javax-activation = "1.1.1"
|
||||
|
||||
korlibs = "5.4.0"
|
||||
uuid = "0.8.4"
|
||||
ktor = "3.2.1"
|
||||
ktor = "3.2.2"
|
||||
|
||||
ksp = "2.2.0-2.0.2"
|
||||
kotlin-poet = "2.0.0"
|
||||
|
||||
microutils = "0.26.0"
|
||||
microutils = "0.26.1"
|
||||
kslog = "1.5.0"
|
||||
|
||||
versions = "0.52.0"
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.SpecialMutableStateFlow
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.micro_utils.coroutines.subscribeAsync
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
@@ -69,12 +71,16 @@ internal fun <BC : BehaviourContext, T> BC.on(
|
||||
createSubContextAndDoSynchronouslyWithUpdatesFilter(behaviourContextReceiver = { scenarioReceiver(triggerData) })
|
||||
}
|
||||
markerFactory ?.let {
|
||||
subscribeSafelyWithoutExceptionsAsync(
|
||||
subscribeAsync(
|
||||
scope,
|
||||
{ markerFactory(it.second) },
|
||||
block = handler
|
||||
)
|
||||
} ?: subscribeLoggingDropExceptions(scope) {
|
||||
logger = Log
|
||||
) {
|
||||
runCatchingLogging(logger = Log) {
|
||||
handler(it)
|
||||
}
|
||||
}
|
||||
} ?: subscribeLoggingDropExceptions(scope, logger = Log) {
|
||||
scope.launchWithBotLogger {
|
||||
handler(it)
|
||||
}
|
||||
|
||||
@@ -30491,6 +30491,11 @@ public final class dev/inmo/tgbotapi/utils/ByteReadChannelAllocatorDeserializati
|
||||
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/utils/CausedByCancellationKt {
|
||||
public static final fun causedCancellationException (Ljava/lang/Throwable;)Ljava/util/concurrent/CancellationException;
|
||||
public static final fun isCausedByCancellation (Ljava/lang/Throwable;)Z
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.bot.ktor.base
|
||||
|
||||
import dev.inmo.kslog.common.*
|
||||
import dev.inmo.micro_utils.coroutines.runCatchingLogging
|
||||
import dev.inmo.tgbotapi.bot.BaseRequestsExecutor
|
||||
import dev.inmo.tgbotapi.bot.exceptions.BotException
|
||||
import dev.inmo.tgbotapi.bot.exceptions.CommonBotException
|
||||
@@ -16,6 +17,7 @@ import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.statement.*
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class DefaultKtorRequestsExecutor internal constructor(
|
||||
@@ -47,7 +49,7 @@ class DefaultKtorRequestsExecutor internal constructor(
|
||||
}
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return runCatching {
|
||||
return runCatchingLogging(logger = logger) {
|
||||
logger.v { "Start request $request" }
|
||||
pipelineStepsHolder.onBeforeSearchCallFactory(request, callsFactories)
|
||||
requestsLimiter.limit(request) {
|
||||
@@ -95,6 +97,7 @@ class DefaultKtorRequestsExecutor internal constructor(
|
||||
CommonBotException(cause = e)
|
||||
} ?: exceptionResult.getOrThrow()
|
||||
}
|
||||
is CancellationException,
|
||||
is BotException -> e
|
||||
else -> CommonBotException(cause = e)
|
||||
}.also { newException ->
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import kotlinx.coroutines.CancellationException
|
||||
|
||||
fun Throwable.causedCancellationException(): CancellationException? {
|
||||
var current = this
|
||||
while (current !is CancellationException) {
|
||||
when {
|
||||
// It is possible, that API will be changed and cancellation will be caused by something else
|
||||
current is CancellationException && current.cause == null -> return current
|
||||
else -> current = current.cause ?: return null
|
||||
}
|
||||
}
|
||||
|
||||
return current
|
||||
}
|
||||
|
||||
fun Throwable.isCausedByCancellation(): Boolean = causedCancellationException() == null
|
||||
@@ -19,7 +19,7 @@ private inline fun CreateDefaultKSLogger(
|
||||
): KSLog {
|
||||
val filter: MessageFilter? = if (dropCancellationExceptions) {
|
||||
{ ll, message, e ->
|
||||
e !is CancellationException
|
||||
e ?.isCausedByCancellation() != true
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
@file:Suppress("OPT_IN_USAGE")
|
||||
|
||||
package dev.inmo.tgbotapi.ksp.processor
|
||||
|
||||
import com.google.devtools.ksp.KspExperimental
|
||||
import com.google.devtools.ksp.getAnnotationsByType
|
||||
import com.google.devtools.ksp.isAnnotationPresent
|
||||
import com.google.devtools.ksp.symbol.*
|
||||
import com.squareup.kotlinpoet.*
|
||||
|
||||
@@ -15,6 +15,8 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import dev.inmo.tgbotapi.updateshandlers.*
|
||||
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
|
||||
import dev.inmo.tgbotapi.utils.causedCancellationException
|
||||
import dev.inmo.tgbotapi.utils.isCausedByCancellation
|
||||
import dev.inmo.tgbotapi.utils.subscribeWithBotLogger
|
||||
import io.ktor.client.plugins.HttpRequestTimeoutException
|
||||
import io.ktor.utils.io.CancellationException
|
||||
@@ -106,7 +108,7 @@ fun TelegramBot.longPollingFlow(
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
if (it is CancellationException) {
|
||||
it.causedCancellationException() ?.let {
|
||||
cancel(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:Suppress("INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING")
|
||||
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:Suppress("INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING")
|
||||
|
||||
package dev.inmo.tgbotapi.webapps
|
||||
|
||||
import dev.inmo.micro_utils.language_codes.IetfLang
|
||||
|
||||
Reference in New Issue
Block a user