From ca4beee95f859805b5a5cd7e39ecd23b7e35f27d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 5 Jun 2020 14:25:19 +0600 Subject: [PATCH] add PossiblySentViaBotCommonMessage and fix error in build --- CHANGELOG.md | 6 ++++-- .../types/message/ChannelMessage.kt | 3 ++- .../types/message/CommonMessageImpl.kt | 3 ++- .../TelegramBotAPI/types/message/RawMessage.kt | 15 +++++++-------- .../abstracts/PossiblySentViaBotCommonMessage.kt | 6 ++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/abstracts/PossiblySentViaBotCommonMessage.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f834ad8471..25c016e183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,8 +53,10 @@ * `TelegramBotAPI`: * Interface `PossiblySentViaBot` has been added - * Currently, only `ChannelMessage` and `CommonMessageImpl` are implementing interface `PossiblySentViaBot`. It - could be changed in future + * Additional interface `PossiblySentViaBotCommonMessage` was added for more explicit typing declaration for + compiler + * Currently, only `ChannelMessage` and `CommonMessageImpl` are implementing the interface + `PossiblySentViaBotCommonMessage`. It could be changed in future * Factory `buildMimeType` was added * `BuiltinMimeTypes` was added * Abstraction `ThumbedWithMimeTypeInlineQueryResult` with `thumbMimeType` field was added diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt index bcd9e41b0c..15bea82224 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMa import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage import com.soywiz.klock.DateTime data class ChannelMessage( @@ -18,4 +19,4 @@ data class ChannelMessage( override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, val authorSignature: AuthorSignature? -) : CommonMessage, PossiblySentViaBot +) : PossiblySentViaBotCommonMessage diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt index 9db1300557..08c2b32bab 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt @@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMa import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.PossiblySentViaBotCommonMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.SuccessfulPaymentInfo import com.soywiz.klock.DateTime @@ -20,4 +21,4 @@ data class CommonMessageImpl( override val replyMarkup: InlineKeyboardMarkup?, override val senderBot: CommonBot?, val paymentInfo: SuccessfulPaymentInfo? -) : Message, CommonMessage, PossiblySentViaBot, FromUserMessage \ No newline at end of file +) : PossiblySentViaBotCommonMessage, FromUserMessage \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 9f9eee6167..92ef9049ea 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -148,7 +148,7 @@ internal data class RawMessage( ) forward_from_chat is ChannelChat -> ForwardFromChannelInfo( forward_date, - forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"), + forward_from_message_id ?: error("Channel forwarded message must contain message id, but was not"), forward_from_chat, forward_signature ) @@ -209,7 +209,7 @@ internal data class RawMessage( chatEvent as? ChannelEvent ?: throwWrongChatEvent(ChannelEvent::class, chatEvent), date.asDate ) - else -> throw IllegalStateException("Expected one of the public chats, but was $chat (in extracting of chat event message)") + else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)") } } ?: content?.let { content -> media_group_id?.let { @@ -222,7 +222,7 @@ internal data class RawMessage( when (content) { is PhotoContent -> content is VideoContent -> content - else -> throw IllegalStateException("Unsupported content for media group") + else -> error("Unsupported content for media group") }, edit_date?.asDate, forwarded, @@ -238,7 +238,7 @@ internal data class RawMessage( when (content) { is PhotoContent -> content is VideoContent -> content - else -> throw IllegalStateException("Unsupported content for media group") + else -> error("Unsupported content for media group") }, edit_date?.asDate, forwarded, @@ -261,8 +261,7 @@ internal data class RawMessage( ) else -> CommonMessageImpl( messageId, - from - ?: throw IllegalStateException("Was detected common message, but owner (sender) of the message was not found"), + from ?: error("Was detected common message, but owner (sender) of the message was not found"), chat, content, date.asDate, @@ -274,7 +273,7 @@ internal data class RawMessage( paymentInfo ) } - } ?: throw IllegalStateException("Was not found supported type of data") + } ?: error("Was not found supported type of data") } catch (e: Exception) { UnknownMessageType( messageId, @@ -286,6 +285,6 @@ internal data class RawMessage( } private fun throwWrongChatEvent(expected: KClass<*>, but: ChatEvent): CommonEvent { - throw IllegalStateException("Wrong type of chat event: expected $expected, but was $but") + error("Wrong type of chat event: expected $expected, but was $but") } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/abstracts/PossiblySentViaBotCommonMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/abstracts/PossiblySentViaBotCommonMessage.kt new file mode 100644 index 0000000000..c13c9548c6 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/abstracts/PossiblySentViaBotCommonMessage.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.PossiblySentViaBot + +interface PossiblySentViaBotCommonMessage : CommonMessage, PossiblySentViaBot diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8ef06692c2..3c46198fce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip