From a193ef5fd5f2fc9f0762ef1156d4f2967dbd33c5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 4 Dec 2020 16:29:50 +0600 Subject: [PATCH] buildBot --- CHANGELOG.md | 2 ++ .../tgbotapi/extensions/api/BotBuilder.kt | 22 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a679c38ed..8d06c6b8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Klock`: `2.0.0` -> `2.0.1` * `Ktor`: `1.4.2` -> `1.4.3` * `MicroUtils`: `0.4.6` -> `0.4.9` +* `API Extensions`: + * New function `buildBot` ## 0.30.9 diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotBuilder.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotBuilder.kt index 9e64ded426..9e3c3dd8f5 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotBuilder.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotBuilder.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.api import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper +import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl import io.ktor.client.HttpClient import io.ktor.client.HttpClientConfig import io.ktor.client.engine.* @@ -36,10 +37,25 @@ data class BotBuilder internal constructor( * @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and * [block] */ +fun buildBot( + token: String, + apiUrl: String = telegramBotAPIDefaultUrl, + block: BotBuilder.() -> Unit +) = telegramBot( + TelegramAPIUrlsKeeper(token, apiUrl), + BotBuilder().apply(block).createHttpClient() +) + +/** + * @return Created by [telegramBotWithCustomClientConfig] function [TelegramBot]. This executor will be preconfigured using [token] and + * [block] + */ +@Deprecated("Renamed", ReplaceWith("buildBot", "dev.inmo.tgbotapi.extensions.api.buildBot")) fun telegramBot( token: String, block: BotBuilder.() -> Unit -): TelegramBot = telegramBot( - TelegramAPIUrlsKeeper(token), - BotBuilder().apply(block).createHttpClient() +): TelegramBot = buildBot( + token, + telegramBotAPIDefaultUrl, + block )