1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-01 23:45:25 +00:00
tgbotapi/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/BotExtensions.kt

167 lines
5.2 KiB
Kotlin
Raw Normal View History

package dev.inmo.tgbotapi.extensions.api
2020-05-12 12:52:37 +00:00
2020-10-04 11:06:30 +00:00
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
2020-11-06 06:07:46 +00:00
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
2020-05-12 12:52:37 +00:00
import io.ktor.client.HttpClient
import io.ktor.client.HttpClientConfig
2020-11-06 06:29:51 +00:00
import io.ktor.client.engine.*
2020-05-12 12:52:37 +00:00
2020-11-06 12:52:59 +00:00
/**
* Allows to create bot using bot [urlsKeeper]
*/
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper
): TelegramBot = KtorRequestsExecutor(
urlsKeeper,
HttpClient()
)
2020-05-12 12:52:37 +00:00
/**
* Allows to create bot using bot [urlsKeeper] and already prepared [client]
*/
fun telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper,
2020-11-06 12:52:59 +00:00
client: HttpClient
): TelegramBot = KtorRequestsExecutor(
2020-05-12 12:52:37 +00:00
urlsKeeper,
client
)
2020-11-06 06:29:51 +00:00
/**
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngineFactory] by passing [clientFactory] param and optionally
* configure it with [clientConfig]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun <T: HttpClientEngineConfig> telegramBot(
urlsKeeper: TelegramAPIUrlsKeeper,
clientFactory: HttpClientEngineFactory<T>,
noinline clientConfig: HttpClientConfig<T>.() -> Unit = {}
) = telegramBot(
urlsKeeper,
HttpClient(clientFactory, clientConfig)
)
2020-05-12 12:52:37 +00:00
/**
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
*/
2020-11-06 06:29:51 +00:00
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper: TelegramAPIUrlsKeeper,
clientEngine: HttpClientEngine,
2020-11-06 06:29:51 +00:00
noinline clientConfig: HttpClientConfig<*>.() -> Unit = {}
) = telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper,
HttpClient(clientEngine, clientConfig)
)
/**
2020-11-06 06:29:51 +00:00
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by configuring [HttpClient] using
* [clientConfig]
2020-05-12 12:52:37 +00:00
*/
2020-11-06 06:29:51 +00:00
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper: TelegramAPIUrlsKeeper,
2020-11-06 06:29:51 +00:00
noinline clientConfig: HttpClientConfig<*>.() -> Unit
) = telegramBot(
2020-05-12 12:52:37 +00:00
urlsKeeper,
HttpClient(clientConfig)
)
2020-11-06 12:52:59 +00:00
/**
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
token: String,
apiUrl: String = telegramBotAPIDefaultUrl
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl))
2020-05-12 12:52:37 +00:00
/**
2020-11-06 06:29:51 +00:00
* Allows to create bot using bot [token], [apiUrl] (for custom api servers) and already prepared [client]
2020-05-12 12:52:37 +00:00
*/
2020-11-06 06:29:51 +00:00
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
2020-11-06 06:07:46 +00:00
token: String,
2020-11-06 06:29:51 +00:00
apiUrl: String = telegramBotAPIDefaultUrl,
2020-11-06 12:52:59 +00:00
client: HttpClient
2020-11-06 06:29:51 +00:00
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), client)
2020-05-12 12:52:37 +00:00
2020-11-06 06:29:51 +00:00
@Suppress("NOTHING_TO_INLINE")
inline fun <T: HttpClientEngineConfig> telegramBot(
2020-05-12 12:52:37 +00:00
token: String,
2020-11-06 06:29:51 +00:00
clientFactory: HttpClientEngineFactory<T>,
apiUrl: String = telegramBotAPIDefaultUrl,
noinline clientConfig: HttpClientConfig<T>.() -> Unit = {}
) = telegramBot(
TelegramAPIUrlsKeeper(token, apiUrl),
clientFactory,
clientConfig
)
2020-05-12 12:52:37 +00:00
/**
2020-11-06 06:29:51 +00:00
* Allows to create bot using bot [token] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
* configure [HttpClient] using [clientConfig]
2020-05-12 12:52:37 +00:00
*/
2020-11-06 06:29:51 +00:00
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
2020-05-12 12:52:37 +00:00
token: String,
2020-11-06 06:29:51 +00:00
clientEngine: HttpClientEngine,
2020-11-06 06:07:46 +00:00
apiUrl: String = telegramBotAPIDefaultUrl,
2020-11-06 06:29:51 +00:00
noinline clientConfig: HttpClientConfig<*>.() -> Unit = {}
) = telegramBot(
TelegramAPIUrlsKeeper(token, apiUrl),
clientEngine,
clientConfig
)
2020-11-06 06:07:46 +00:00
2020-11-06 06:29:51 +00:00
/**
* Allows to create bot using bot [token] and [apiUrl] and specify [HttpClientEngine] by configuring [HttpClient] using
* [clientConfig]
*/
2020-11-06 06:07:46 +00:00
@Suppress("NOTHING_TO_INLINE")
2020-11-06 06:29:51 +00:00
inline fun telegramBot(
2020-11-06 06:07:46 +00:00
token: String,
apiUrl: String = telegramBotAPIDefaultUrl,
2020-11-06 12:52:59 +00:00
noinline clientConfig: HttpClientConfig<*>.() -> Unit
2020-11-06 06:29:51 +00:00
) = telegramBot(
TelegramAPIUrlsKeeper(token, apiUrl),
clientConfig
)
2020-05-12 12:52:37 +00:00
/**
2020-11-06 06:29:51 +00:00
* Allows to create bot using bot [urlsKeeper] and specify [HttpClientEngine] by passing [clientEngine] param and optionally
2020-05-12 12:52:37 +00:00
* configure [HttpClient] using [clientConfig]
*/
2020-11-06 06:29:51 +00:00
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
2020-05-12 12:52:37 +00:00
clientEngine: HttpClientEngine,
2020-11-06 06:29:51 +00:00
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientEngine, clientConfig)
)
/**
* Allows to create bot using bot [urlsKeeper] and optionally configure [HttpClient] using [clientConfig]
*/
@Deprecated("Will be removed in next releases", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
fun telegramBotWithCustomClientConfig(
urlsKeeper: TelegramAPIUrlsKeeper,
clientConfig: HttpClientConfig<*>.() -> Unit
): TelegramBot = telegramBot(
urlsKeeper,
HttpClient(clientConfig)
)
@Suppress("NOTHING_TO_INLINE")
@Deprecated("Renamed", ReplaceWith("telegramBot", "dev.inmo.tgbotapi.extensions.api.telegramBot"))
inline fun telegramBotWithCustomClientConfig(
token: String,
2020-11-06 06:07:46 +00:00
apiUrl: String = telegramBotAPIDefaultUrl,
2020-11-06 06:29:51 +00:00
noinline clientConfig: HttpClientConfig<*>.() -> Unit
) = telegramBot(token, apiUrl = apiUrl, clientConfig = clientConfig)