1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

BotBuilder fixes

This commit is contained in:
InsanusMokrassar 2020-06-02 21:18:49 +06:00
parent 7ede53fdbb
commit 22e8b06fda
2 changed files with 16 additions and 5 deletions

View File

@ -68,6 +68,8 @@
* `TelegramBotAPI-extensions-api`: * `TelegramBotAPI-extensions-api`:
* A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing * A lot of `RequesstExecutor#getChat` extensions was added for more explicit types showing
* New `RequesstExecutor#setMyCommands` extension was added * New `RequesstExecutor#setMyCommands` extension was added
* New field `BotBuilder#ktorClientEngineFactory` introduced
* Field `BotBuilder#ktorClientEngine` now is deprecated
* `TelegramBotAPI-extensions-utils`: * `TelegramBotAPI-extensions-utils`:
* `safely` function was introduced. It is in `PreviewFeature` state currently * `safely` function was introduced. It is in `PreviewFeature` state currently
* `makeLinkToMessage` extensions has been added * `makeLinkToMessage` extensions has been added

View File

@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig import io.ktor.client.HttpClientConfig
import io.ktor.client.engine.HttpClientEngine import io.ktor.client.engine.*
import io.ktor.client.engine.ProxyConfig
/** /**
* @param proxy Standard ktor [ProxyConfig] * @param proxy Standard ktor [ProxyConfig]
@ -14,20 +13,30 @@ import io.ktor.client.engine.ProxyConfig
*/ */
data class BotBuilder internal constructor( data class BotBuilder internal constructor(
var proxy: ProxyConfig? = null, var proxy: ProxyConfig? = null,
@Deprecated("ktorClientEngineFactory parameter will be used preferable. In future this parameter will be removed")
var ktorClientEngine: HttpClientEngine? = null, var ktorClientEngine: HttpClientEngine? = null,
var ktorClientEngineFactory: HttpClientEngineFactory<out HttpClientEngineConfig>? = null,
var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null var ktorClientConfig: (HttpClientConfig<*>.() -> Unit) ? = null
) { ) {
internal fun createHttpClient(): HttpClient = ktorClientEngine ?.let { engine -> internal fun createHttpClient(): HttpClient = ktorClientEngineFactory ?.let {
HttpClient(
it.create {
this@create.proxy = this@BotBuilder.proxy ?: this@create.proxy
}
) {
ktorClientConfig ?.let { it() }
}
} ?: ktorClientEngine ?.let { engine ->
HttpClient(engine) { HttpClient(engine) {
ktorClientConfig ?.let { it() } ktorClientConfig ?.let { it() }
engine { engine {
proxy = this@BotBuilder.proxy ?: proxy this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy
} }
} }
} ?: HttpClient { } ?: HttpClient {
ktorClientConfig ?.let { it() } ktorClientConfig ?.let { it() }
engine { engine {
proxy = this@BotBuilder.proxy ?: proxy this@engine.proxy = this@BotBuilder.proxy ?: this@engine.proxy
} }
} }
} }