1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

add PossiblySentViaBotCommonMessage and fix error in build

This commit is contained in:
InsanusMokrassar 2020-06-05 14:25:19 +06:00
parent ca784e67df
commit ca4beee95f
6 changed files with 22 additions and 13 deletions

View File

@ -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

View File

@ -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<T: MessageContent>(
@ -18,4 +19,4 @@ data class ChannelMessage<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
val authorSignature: AuthorSignature?
) : CommonMessage<T>, PossiblySentViaBot
) : PossiblySentViaBotCommonMessage<T>

View File

@ -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<T: MessageContent>(
override val replyMarkup: InlineKeyboardMarkup?,
override val senderBot: CommonBot?,
val paymentInfo: SuccessfulPaymentInfo?
) : Message, CommonMessage<T>, PossiblySentViaBot, FromUserMessage
) : PossiblySentViaBotCommonMessage<T>, FromUserMessage

View File

@ -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")
}
}

View File

@ -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<T: MessageContent> : CommonMessage<T>, PossiblySentViaBot

View File

@ -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