2020-10-04 11:06:30 +00:00
|
|
|
package dev.inmo.tgbotapi.utils
|
2019-07-25 08:25:18 +00:00
|
|
|
|
2020-11-06 06:07:46 +00:00
|
|
|
const val telegramBotAPIDefaultUrl = "https://api.telegram.org"
|
|
|
|
|
2020-11-17 07:18:11 +00:00
|
|
|
private inline val String.withoutLastSlash: String
|
|
|
|
get() {
|
|
|
|
var correctedUrl = this
|
|
|
|
while (true) {
|
|
|
|
val withoutSuffix = correctedUrl.removeSuffix("/")
|
|
|
|
if (withoutSuffix == correctedUrl) {
|
|
|
|
return correctedUrl
|
|
|
|
}
|
|
|
|
correctedUrl = withoutSuffix
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 08:25:18 +00:00
|
|
|
class TelegramAPIUrlsKeeper(
|
|
|
|
token: String,
|
2020-11-06 06:07:46 +00:00
|
|
|
hostUrl: String = telegramBotAPIDefaultUrl
|
2019-07-25 08:25:18 +00:00
|
|
|
) {
|
2020-11-17 07:18:11 +00:00
|
|
|
val commonAPIUrl: String
|
|
|
|
val fileBaseUrl: String
|
|
|
|
|
|
|
|
init {
|
|
|
|
val correctedHost = hostUrl.withoutLastSlash
|
|
|
|
commonAPIUrl = "$correctedHost/bot$token"
|
|
|
|
fileBaseUrl = "$correctedHost/file/bot$token"
|
|
|
|
}
|
2019-07-25 08:25:18 +00:00
|
|
|
}
|