diff --git a/CHANGELOG.md b/CHANGELOG.md index 886233b3b0..1a14abb39f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # TelegramBotAPI changelog +## 0.13.0 Telegram Polls + +* Type `PollOption` and `AnonymousPollOption` added +* Type `Poll` added +* Type `PollUpdate` added and implemented in `RawUpdate`. Now `PollUpdate` can be retrieved from `RawUpdate` +* Type `PollContent` added - now it can be a value of `ContentMessage#content` +* Request `SendPoll` added and `PollContent#createResend` now use it +* `ByInlineMessageId` is deprecated (use `InlineMessageAction` instead) +* `ByMessageId` is deprecated (use `MessageAction` instead) +* Most part of requests which are working with identifiers of messages now implement `MessageAction` directly or +by their parents +* `StopPoll` implemented +* All current `Chat` abstractions are deprecated and rewritten as typealiases. Use `Chat` abstractions from +`com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts` package +* Common Groups now may have pinned message +* `is_member` field added into `RestrictedChatMember` +* **BREAK CHANGES** Now `ForwardedMessages` can be `AnonymousForwardedMessage` and `PublicForwardedMessage`. Old +implementations now extend `PublicForwardedMessage` + ## 0.12.0 Webhooks * Added `DataRequest` interface which replace `Data` interface diff --git a/README.md b/README.md index a26b2cde92..37b4ed1e7a 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,7 @@ solves or unuseful moments are describing by official [Telegram Bot API](https:/ ## Compatibility -This version compatible with [July 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#july-26-2018). That means that -most part of API has been implemented (according to last [August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#august-27-2018)) -except the Passport API which will be included as soon as possible. All included and supported API +This version compatible with [14th of April 2019 update of TelegramBotAPI](https://core.telegram.org/bots/api#april-14-2019). There is one exception of implemented functionality. It is Telegram Passport API, which was presented in [August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#august-27-2018) update. It will be implemented as soon as possible. All included and supported API can be found on [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Included-API). ## How to implement library? diff --git a/build.gradle b/build.gradle index f33328bda1..e6e1a82bd5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -project.version = "0.12.7" +project.version = "0.13.0" project.group = "com.github.insanusmokrassar" buildscript { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByInlineMessageId.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByInlineMessageId.kt index b163e044e5..a2b66df4b6 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByInlineMessageId.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByInlineMessageId.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types -import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier - -interface ByInlineMessageId { - val inlineMessageId: InlineMessageIdentifier -} \ No newline at end of file +@Deprecated( + "Deprecated for the reason of creating of more obvious type interface", + ReplaceWith("InlineMessageAction", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction") +) +typealias ByInlineMessageId = InlineMessageAction \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByMessageId.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByMessageId.kt index 768c99e312..e208e86096 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByMessageId.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/ByMessageId.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types -import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +@Deprecated( + "Deprecated for the reason of creating of more obvious type interface", + ReplaceWith("MessageAction", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction") -interface ByMessageId : ChatRequest { - val messageId: MessageIdentifier -} \ No newline at end of file +) +typealias ByMessageId = MessageAction \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/InlineMessageAction.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/InlineMessageAction.kt new file mode 100644 index 0000000000..fa0a1ad1ae --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/InlineMessageAction.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types + +import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier + +interface InlineMessageAction { + val inlineMessageId: InlineMessageIdentifier +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/MessageAction.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/MessageAction.kt new file mode 100644 index 0000000000..51323f9b59 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/MessageAction.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types + +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier + +interface MessageAction: ChatRequest { + val messageId: MessageIdentifier +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt index c5e4341d15..60158eafdf 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/DeleteMessage.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* @@ -8,10 +9,10 @@ import kotlinx.serialization.internal.BooleanSerializer @Serializable data class DeleteMessage( @SerialName(chatIdField) - val chatId: ChatIdentifier, + override val chatId: ChatIdentifier, @SerialName(messageIdField) - val messageId: MessageIdentifier -) : SimpleRequest { + override val messageId: MessageIdentifier +) : SimpleRequest, MessageAction { override fun method(): String = "deleteMessage" override fun resultSerializer(): KSerializer = BooleanSerializer diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt index 8fa1281ad4..71294b1b7c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/ForwardMessage.kt @@ -1,5 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage @@ -12,10 +13,14 @@ data class ForwardMessage( @SerialName(chatIdField) val toChatId: ChatIdentifier, @SerialName(messageIdField) - val messageId: MessageIdentifier, + override val messageId: MessageIdentifier, @SerialName(disableNotificationField) val disableNotification: Boolean = false -): SimpleRequest { +): SimpleRequest, MessageAction { + @Transient + override val chatId: ChatIdentifier + get() = fromChatId + override fun method(): String = "forwardMessage" override fun resultSerializer(): KSerializer = RawMessage.serializer() diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt new file mode 100644 index 0000000000..8f5a4118f0 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt @@ -0,0 +1,22 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll +import kotlinx.serialization.* + +@Serializable +data class StopPoll( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageIdField) + override val messageId: MessageIdentifier, + @SerialName(replyMarkupField) + override val replyMarkup: InlineKeyboardMarkup? +) : MessageAction, SimpleRequest, ReplyMarkup { + override fun method(): String = "stopPoll" + override fun resultSerializer(): KSerializer = Poll.serializer() +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt index f9c74c5309..8d7067c695 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/modify/PinChatMessage.kt @@ -1,7 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableNotification +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* @@ -12,10 +11,10 @@ data class PinChatMessage ( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(messageIdField) - val messageId: MessageIdentifier, + override val messageId: MessageIdentifier, @SerialName(disableNotificationField) override val disableNotification: Boolean = false -): ChatRequest, SimpleRequest, DisableNotification { +): ChatRequest, SimpleRequest, MessageAction, DisableNotification { override fun method(): String = "pinChatMessage" override fun resultSerializer(): KSerializer = BooleanSerializer } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditChatMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditChatMessage.kt index ac9c02a798..5400523a1d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditChatMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/edit/abstracts/EditChatMessage.kt @@ -1,11 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -interface EditChatMessage : SimpleRequest { - val chatId: ChatIdentifier - val messageId: MessageIdentifier -} \ No newline at end of file +interface EditChatMessage : SimpleRequest, MessageAction diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt index 47d96d04b0..29fd440756 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByChat.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.SerialName @@ -14,4 +14,4 @@ data class GetGameHighScoresByChat ( override val chatId: ChatId, @SerialName(messageIdField) override val messageId: MessageIdentifier -) : GetGameHighScores, ByMessageId +) : GetGameHighScores, MessageAction diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt index b5e7aadc2e..e6b0d1f94e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/GetGameHighScoresByInlineMessageId.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.SerialName @@ -12,4 +12,4 @@ data class GetGameHighScoresByInlineMessageId ( override val userId: UserId, @SerialName(inlineMessageIdField) override val inlineMessageId: InlineMessageIdentifier -) : GetGameHighScores, ByInlineMessageId +) : GetGameHighScores, InlineMessageAction diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt index 5c724b2c0c..5f4ede6eb3 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByChatId.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.SerialName @@ -20,4 +20,4 @@ data class SetGameScoreByChatId ( override val force: Boolean = false, @SerialName(disableEditMessageField) override val disableEditMessage: Boolean = false -) : SetGameScore, ByMessageId +) : SetGameScore, MessageAction diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt index fcdec16441..ebc1d15041 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/games/SetGameScoreByInlineMessageId.kt @@ -1,6 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.SerialName @@ -18,4 +18,4 @@ data class SetGameScoreByInlineMessageId ( override val force: Boolean = false, @SerialName(disableEditMessageField) override val disableEditMessage: Boolean = false -) : SetGameScore, ByInlineMessageId +) : SetGameScore, InlineMessageAction diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt new file mode 100644 index 0000000000..8a9eee0b57 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt @@ -0,0 +1,45 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.send + +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.KSerializer +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SendPoll( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(questionField) + val question: String, + @SerialName(optionsField) + val options: List, + @SerialName(disableNotificationField) + override val disableNotification: Boolean = false, + @SerialName(replyToMessageIdField) + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(replyMarkupField) + override val replyMarkup: KeyboardMarkup? = null +) : SendMessageRequest, + ReplyingMarkupSendMessageRequest { + + init { + if (question.length !in pollQuestionTextLength) { + throw IllegalArgumentException("The length of questions for polls must be in $pollQuestionTextLength range, but was ${question.length}") + } + options.forEach { + if (it.length !in pollOptionTextLength) { + throw IllegalArgumentException("The length of question option text for polls must be in $pollOptionTextLength range, but was ${it.length}") + } + } + if (options.size !in pollOptionsLimit) { + throw IllegalArgumentException("The amount of question options for polls must be in $pollOptionsLimit range, but was ${options.size}") + } + } + + override fun method(): String = "sendPoll" + override fun resultSerializer(): KSerializer = RawMessage.serializer() +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt index 11c24ed191..b2037bbb81 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RawChatMember.kt @@ -26,6 +26,8 @@ data class RawChatMember( private val canPinMessages: Boolean = false, @SerialName(canPromoteMembersField) private val canPromoteMembers: Boolean = false, + @SerialName(isMemberField) + private val isMember: Boolean = false, @SerialName(canSendMessagesField) private val canSendMessages: Boolean = false, @SerialName(canSendMediaMessagesField) @@ -55,6 +57,7 @@ data class RawChatMember( "restricted" -> RestrictedChatMember( user, until_date, + isMember, canSendMessages, canSendMediaMessages, canSendOtherMessages, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt index ce0c2df476..a6ab6358bd 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt @@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.User data class RestrictedChatMember( override val user: User, override val untilDate: TelegramDate?, + val isMember: Boolean, val canSendMessages: Boolean, val canSendMediaMessages: Boolean, val canSendOtherMessages: Boolean, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 59c81efe57..9122be4efe 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -6,6 +6,7 @@ typealias InlineQueryIdentifier = String typealias UpdateIdentifier = Long typealias MediaGroupIdentifier = String typealias ForwardSignature = String +typealias ForwardSenderName = String typealias AuthorSignature = ForwardSignature typealias CallbackQueryIdentifier = String typealias PaymentQueryIdentifier = String @@ -15,6 +16,7 @@ typealias InvoicePayload = String typealias ShippingOptionIdentifier = String typealias StartParameter = String typealias InlineMessageIdentifier = String +typealias PollIdentifier = String val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 until 1024 @@ -29,6 +31,10 @@ val invoiceTitleLimit = 1 until 32 val invoiceDescriptionLimit = 1 until 256 val invoicePayloadBytesLimit = 1 until 128 +val pollOptionTextLength = 1 .. 100 +val pollQuestionTextLength = 1 until 256 +val pollOptionsLimit = 2 .. 10 + val livePeriodLimit = 60 .. 86400 val inlineQueryAnswerResultsLimit = 0 .. 50 @@ -75,6 +81,8 @@ const val hasCustomCertificateField = "has_custom_certificate" const val pendingUpdateCountField = "pending_update_count" const val lastErrorDateField = "last_error_date" const val lastErrorMessageField = "last_error_message" +const val votesCountField = "voter_count" +const val isClosedField = "is_closed" const val photoUrlField = "photo_url" @@ -124,6 +132,7 @@ const val inputMessageContentField = "input_message_content" const val hideUrlField = "hide_url" +const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" const val canSendMediaMessagesField = "can_send_media_messages" const val canSendOtherMessagesField = "can_send_other_messages" @@ -180,6 +189,8 @@ const val payloadField = "payload" const val vcardField = "vcard" const val resultsField = "results" const val certificateField = "certificate" +const val questionField = "question" +const val optionsField = "options" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt index cf0612a4fb..8e11c95934 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt @@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField -import kotlinx.serialization.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable @Serializable data class InputMediaAnimation( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt index 629d3fea16..e95b209f36 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/InputMedia/InputMediaDocument.kt @@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField -import kotlinx.serialization.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable @Serializable data class InputMediaDocument( diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt index 244350736c..598b991822 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt @@ -1,14 +1,16 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class ChannelChat( override val id: ChatId, override val title: String? = null, - val username: Username? = null, - val description: String? = null, + override val username: Username? = null, + override val description: String? = null, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, - val pinnedMessage: RawMessage? -) : PublicChat + override val pinnedMessage: RawMessage? +) : PublicChat, UsernameChat, DescriptionChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt index 5531325b90..9f38f83d41 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt @@ -1,9 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -interface Chat { - val id: ChatId - val chatPhoto: ChatPhoto? -} \ No newline at end of file +@Deprecated( + "Replaced into another package", + ReplaceWith("Chat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat") +) +typealias Chat = Chat \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt index 1e9c15bd6c..570d671d1a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt @@ -1,15 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat -interface GroupChat : PublicChat { - val allMembersAreAdmins: Boolean -} - -data class GroupChatImpl( - override val id: ChatId, - override val title: String? = null, - override val allMembersAreAdmins: Boolean, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null) : GroupChat +@Deprecated( + "Replaced into another package", + ReplaceWith("GroupChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat") +) +typealias GroupChat = GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt new file mode 100644 index 0000000000..0b06bf6e64 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -0,0 +1,15 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class GroupChatImpl( + override val id: ChatId, + override val title: String? = null, + override val allMembersAreAdmins: Boolean, + override val inviteLink: String? = null, + override val chatPhoto: ChatPhoto? = null, + override val pinnedMessage: RawMessage? = null +) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt index f266426398..0f7f79fd7b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt @@ -1,11 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat data class PrivateChat( override val id: ChatId, - val username: Username? = null, + override val username: Username? = null, val firstName: String? = null, val lastName: String? = null, override val chatPhoto: ChatPhoto? = null -) : Chat +) : Chat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt index 27087007df..fbfb55226d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt @@ -1,6 +1,9 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -interface PublicChat : Chat { - val title: String? - val inviteLink: String? -} +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat + +@Deprecated( + "Replaced into another package", + ReplaceWith("PublicChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat") +) +typealias PublicChat = PublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index 69e3a91896..d7a77e61b0 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt index 3a1232e4fb..b310b22b6a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt @@ -1,17 +1,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class SupergroupChat( override val id: ChatId, override val title: String? = null, - val username: Username? = null, - val description: String? = null, + override val username: Username? = null, + override val description: String? = null, override val allMembersAreAdmins: Boolean, override val inviteLink: String? = null, override val chatPhoto: ChatPhoto? = null, - val pinnedMessage: RawMessage? = null, + override val pinnedMessage: RawMessage? = null, val stickerSetName: String? = null, val canSetStickerSet: Boolean -) : GroupChat +) : GroupChat, UsernameChat, DescriptionChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt new file mode 100644 index 0000000000..7b84aa73b7 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto + +interface Chat { + val id: ChatId + val chatPhoto: ChatPhoto? +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt new file mode 100644 index 0000000000..f572b5fcd5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface DescriptionChat : PublicChat { + val description: String? +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt new file mode 100644 index 0000000000..d3ed57909b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface GroupChat : PublicChat { + val allMembersAreAdmins: Boolean +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt new file mode 100644 index 0000000000..de874bb339 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +interface PublicChat : Chat { + val title: String? + val inviteLink: String? + val pinnedMessage: RawMessage? +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/UsernameChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/UsernameChat.kt new file mode 100644 index 0000000000..724f4704e7 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/UsernameChat.kt @@ -0,0 +1,7 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.Username + +interface UsernameChat : Chat { + val username: Username? +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMediaGroupMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMediaGroupMessage.kt index 1a10980a8c..c127d3acbd 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMediaGroupMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMediaGroupMessage.kt @@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt index 781e81d0cd..2754550f26 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelMessage.kt @@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.AuthorSignature import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt index 736eba1fc9..77cad407a4 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMediaGroupMessage.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +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.MediaGroupContent import org.joda.time.DateTime diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt index a926995cd7..94de3da542 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/CommonMessageImpl.kt @@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.User -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +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.payments.abstracts.PaymentInfo diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ForwardedMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ForwardedMessage.kt index b51d365934..8c991da6b7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ForwardedMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ForwardedMessage.kt @@ -1,11 +1,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat sealed class ForwardedMessage { - abstract val messageId: MessageIdentifier abstract val dateOfOriginal: TelegramDate +} + +data class AnonymousForwardedMessage( + override val dateOfOriginal: TelegramDate, + val senderName: String +) : ForwardedMessage() + +sealed class PublicForwardedMessage : ForwardedMessage() { + abstract val messageId: MessageIdentifier abstract val from: User? } @@ -13,7 +21,7 @@ data class CommonForwardedMessage( override val messageId: MessageIdentifier, override val dateOfOriginal: TelegramDate, override val from: User -) : ForwardedMessage() +) : PublicForwardedMessage() data class ForwardedFromChannelMessage( override val messageId: MessageIdentifier, @@ -21,4 +29,4 @@ data class ForwardedFromChannelMessage( override val from: User?, val channelChat: Chat, val signature: String? = null -) : ForwardedMessage() +) : PublicForwardedMessage() diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/GroupEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/GroupEventMessage.kt index 2a2f7b3e45..d97146deca 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/GroupEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/GroupEventMessage.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.GroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import org.joda.time.DateTime diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 30d48e9916..8fc84d4e5d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.chat.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.files.* import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.* @@ -17,6 +18,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.Success import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment +import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll import kotlinx.serialization.* import kotlin.reflect.KClass @@ -35,6 +37,7 @@ data class RawMessage( private val forward_from_chat: RawChat? = null, private val forward_from_message_id: MessageIdentifier? = null, private val forward_signature: ForwardSignature? = null, + private val forward_sender_name: ForwardSenderName? = null, private val forward_date: TelegramDate? = null, private val reply_to_message: RawMessage? = null, private val edit_date: TelegramDate? = null, @@ -59,6 +62,7 @@ data class RawMessage( private val contact: Contact? = null, private val location: Location? = null, private val venue: Venue? = null, + private val poll: Poll? = null, private val new_chat_members: List? = null, private val left_chat_member: User? = null, private val new_chat_title: String? = null, @@ -122,14 +126,16 @@ data class RawMessage( contact != null -> ContactContent(contact) location != null -> LocationContent(location) venue != null -> VenueContent(venue) + poll != null -> PollContent(poll) else -> null } } @Transient private val forwarded: ForwardedMessage? by lazy { + forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field forward_from_message_id ?.let { - forward_date ?: throw IllegalStateException("For forwarded messages date of original message declared as set up required") + forward_from ?: throw IllegalStateException("For common forwarded messages author of original message declared as set up required") forward_from_chat ?.let { ForwardedFromChannelMessage( forward_from_message_id, @@ -142,7 +148,11 @@ data class RawMessage( forward_from_message_id, forward_date, forward_from - ?: throw IllegalStateException("For common forwarded messages author of original message declared as set up required") + ) + } ?: forward_sender_name ?.let { + AnonymousForwardedMessage( + forward_date, + forward_sender_name ) } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt index a448e9f804..602afa1aac 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/abstracts/Message.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import org.joda.time.DateTime interface Message { diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt new file mode 100644 index 0000000000..e6eef2fdff --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt @@ -0,0 +1,28 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.content + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent +import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll + +data class PollContent( + val poll: Poll +) : MessageContent { + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + replyToMessageId: MessageIdentifier?, + replyMarkup: KeyboardMarkup? + ): Request = SendPoll( + chatId, + poll.question, + poll.options.map { it.text }, + disableNotification, + replyToMessageId, + replyMarkup + ) +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt new file mode 100644 index 0000000000..5d15b1a762 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.polls + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class Poll( + @SerialName(idField) + val id: PollIdentifier, + @SerialName(questionField) + val question: String, + @SerialName(optionsField) + val options: List, + @SerialName(isClosedField) + val closed: Boolean = false +) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt new file mode 100644 index 0000000000..c29522aeb5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt @@ -0,0 +1,37 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.polls + +import com.github.insanusmokrassar.TelegramBotAPI.types.textField +import com.github.insanusmokrassar.TelegramBotAPI.types.votesCountField +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor + +@Serializable(PollOptionSerializer::class) +sealed class PollOption { + abstract val text: String + abstract val votes: Int +} + +@Serializable +data class AnonymousPollOption ( + @SerialName(textField) + override val text: String, + @SerialName(votesCountField) + override val votes: Int +) : PollOption() + +object PollOptionSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName(PollOption::class.simpleName ?: "PollOption") + + override fun deserialize(decoder: Decoder): PollOption = AnonymousPollOption.serializer().deserialize( + decoder + ) + + override fun serialize(encoder: Encoder, obj: PollOption) { + when (obj) { + is AnonymousPollOption -> AnonymousPollOption.serializer().serialize( + encoder, + obj + ) + } + } +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/PollUpdate.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/PollUpdate.kt new file mode 100644 index 0000000000..49a6e9131f --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/PollUpdate.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.update + +import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll +import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update + +data class PollUpdate( + override val updateId: UpdateIdentifier, + override val data: Poll +) : Update diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt index 097a200071..1ff2353d5a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/RawUpdate.kt @@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery +import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField import kotlinx.serialization.* @@ -25,7 +26,8 @@ data class RawUpdate constructor( private val chosen_inline_result: RawChosenInlineResult? = null, private val callback_query: RawCallbackQuery? = null, private val shipping_query: ShippingQuery? = null, - private val pre_checkout_query: PreCheckoutQuery? = null + private val pre_checkout_query: PreCheckoutQuery? = null, + private val poll: Poll? = null ) { @Transient val asUpdate: Update by lazy { @@ -40,6 +42,7 @@ data class RawUpdate constructor( callback_query != null -> CallbackQueryUpdate(updateId, callback_query.asCallbackQuery) shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query) pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query) + poll != null -> PollUpdate(updateId, poll) else -> throw IllegalArgumentException("Unsupported type of update") } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt index cb2d16d5c8..3f8961013c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/MediaGroupList.kt @@ -1,7 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.utils import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate