From 865edf385f085157774fb9f798c5ca1d6ec34003 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 22 Mar 2020 14:07:00 +0600 Subject: [PATCH] fix several todo --- CHANGELOG.md | 3 +++ .../requests/send/SendLocation.kt | 1 - .../InlineKeyboardButton.kt | 1 - .../types/buttons/InlineKeyboardMarkup.kt | 18 +++++++++++++++++- .../abstracts/InputFileFromJavaFile.kt | 10 +++++++--- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b43081572c..060c8ae8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * `UUID`: `0.0.7` -> `0.1.0` * `TelegramBotAPI`: * `Bot` implementations (as and `Bot` itself) now have not nullable `username` + * `File#toInputFile` extension now will throw error when file does not exists + * `InlineKeyboardMarkup` will check that `PayInlineKeyboardButton` is the first in case if it is exists in + `keyboard` ## 0.24.0 diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt index 363dee4d01..f06c804c20 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendLocation.kt @@ -16,7 +16,6 @@ import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() -// TODO:: Add location tracker for tracking location @Serializable data class SendLocation( @SerialName(chatIdField) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt index d477c11b18..0c2da03af1 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardButtons/InlineKeyboardButton.kt @@ -9,7 +9,6 @@ sealed class InlineKeyboardButton { abstract val text: String } -//TODO:: add check that this button first in a row (it MUST be first in a row) @Serializable data class PayInlineKeyboardButton( override val text: String, diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardMarkup.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardMarkup.kt index 64d3490c59..7529c49112 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardMarkup.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/buttons/InlineKeyboardMarkup.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.buttons import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.PayInlineKeyboardButton import com.github.insanusmokrassar.TelegramBotAPI.types.inlineKeyboardField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -9,4 +10,19 @@ import kotlinx.serialization.Serializable data class InlineKeyboardMarkup( @SerialName(inlineKeyboardField) val keyboard: Matrix -) : KeyboardMarkup +) : KeyboardMarkup { + init { + val isTherePayButton = keyboard.any { it -> + it.any { + it is PayInlineKeyboardButton + } + } + if (isTherePayButton) { + // first button is not PayInlineKeyboardButton + val firstIsPaymentButton = keyboard.first().firstOrNull() is PayInlineKeyboardButton + if (!firstIsPaymentButton) { + error("In case if PayInlineKeyboardButton included in keyboard - it must ") + } + } + } +} diff --git a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt index 99b52b76e6..58193b52ac 100644 --- a/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt +++ b/TelegramBotAPI/src/jvmMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/abstracts/InputFileFromJavaFile.kt @@ -3,6 +3,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile import java.io.File -fun File.toInputFile() = MultipartFile( - StorageFile(this) -) +fun File.toInputFile() = if (exists()) { + MultipartFile( + StorageFile(this) + ) +} else { + error("Specified file $absolutePath does not exists") +}