1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-03 15:19:30 +00:00

small improvements in long polling and behaviour buildr

This commit is contained in:
2025-06-15 11:38:17 +06:00
parent d19e6ad4e0
commit 429fc5d2f9
13 changed files with 75 additions and 49 deletions

View File

@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.bot
import dev.inmo.kslog.common.KSLog
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
import io.ktor.utils.io.core.Closeable
/**
@@ -12,8 +13,8 @@ import io.ktor.utils.io.core.Closeable
* @see dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor
*/
interface RequestsExecutor : Closeable {
val Log: KSLog?
get() = null
val Log: KSLog
get() = DefaultKTgBotAPIKSLog
/**
* Unsafe execution of incoming [request]. Can throw almost any exception. So, it is better to use
* something like [dev.inmo.tgbotapi.extensions.utils.shortcuts.executeAsync] or

View File

@@ -29,7 +29,7 @@ expect class KtorRequestsExecutor internal constructor(
logger: KSLog,
diff: Unit // just a diff property to know where constructor and where calling function with defaults
) : BaseRequestsExecutor {
override val Log: KSLog?
override val Log: KSLog
override suspend fun <T : Any> execute(request: Request<T>): T
override fun close()
}

View File

@@ -30,7 +30,7 @@ class DefaultKtorRequestsExecutor internal constructor(
private val logger: KSLog,
diff: Unit
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
override val Log: KSLog? = logger
override val Log: KSLog = logger
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
if (!excludeDefaultFactories) {
this@DefaultKtorRequestsExecutor.logger.v { "Installing default factories" }

View File

@@ -49,7 +49,7 @@ class MultipleClientKtorRequestsExecutor(
logger: KSLog,
clientFactory: () -> HttpClient,
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
override val Log: KSLog? = logger
override val Log: KSLog = logger
private val requestExecutors = (0 until requestExecutorsCount).map {
DefaultKtorRequestsExecutor(
telegramAPIUrlsKeeper,

View File

@@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.utils.DefaultKTgBotAPIKSLog
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import kotlinx.coroutines.*
import kotlin.js.JsName
@@ -30,8 +31,8 @@ class SimpleMultiServerRequestsExecutor(
bots.forEach(TelegramBot::close)
}
) : RequestsExecutor {
override val Log: KSLog?
get() = bots.firstNotNullOfOrNull { it.Log }
override val Log: KSLog
get() = bots.firstNotNullOfOrNull { it.Log } ?: DefaultKTgBotAPIKSLog
override suspend fun <T : Any> execute(request: Request<T>): T {
var currentBot = bots.botSelector(-1, null)
while (currentCoroutineContext().isActive) {