From c95c0a0ae0ef000a5c795e7f9a16129f1ef766e2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 14 Apr 2019 18:51:13 +0800 Subject: [PATCH 01/16] start 0.13.0 --- CHANGELOG.md | 2 ++ build.gradle | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 886233b3b0..13f254fb2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.13.0 Telegram Polls + ## 0.12.0 Webhooks * Added `DataRequest` interface which replace `Data` interface 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 { From 0af6e6ca159f3f6cf15b3df28da0cc1ebd84cd31 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 15:45:29 +0800 Subject: [PATCH 02/16] PollOption added --- CHANGELOG.md | 2 + .../TelegramBotAPI/types/Common.kt | 1 + .../types/polls/AnonymousPollOption.kt | 37 +++++++++++++++++++ .../types/polls/abstracts/PollOption.kt | 2 + 4 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f254fb2d..a4fdbc38d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.13.0 Telegram Polls +* `PollOption` added + ## 0.12.0 Webhooks * Added `DataRequest` interface which replace `Data` interface 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..b773f7098e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -75,6 +75,7 @@ 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 photoUrlField = "photo_url" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.kt new file mode 100644 index 0000000000..c29522aeb5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.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/polls/abstracts/PollOption.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt new file mode 100644 index 0000000000..2d18915931 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt @@ -0,0 +1,2 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.polls.abstracts + From b7d214d1451a09f2ae29f719964638451609ae6f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 15:51:53 +0800 Subject: [PATCH 03/16] add Poll object --- CHANGELOG.md | 3 ++- .../TelegramBotAPI/types/Common.kt | 7 +++++++ .../TelegramBotAPI/types/polls/Poll.kt | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/Poll.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index a4fdbc38d5..1e08a5c3e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 0.13.0 Telegram Polls -* `PollOption` added +* Type `PollOption` and `AnonymousPollOption` added +* Type `Poll` added ## 0.12.0 Webhooks 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 b773f7098e..dc44fd8778 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -15,6 +15,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 +30,9 @@ val invoiceTitleLimit = 1 until 32 val invoiceDescriptionLimit = 1 until 256 val invoicePayloadBytesLimit = 1 until 128 +val pollOptionTextLength = 1 .. 100 +val pollQuectionTextLength = 1 until 256 + val livePeriodLimit = 60 .. 86400 val inlineQueryAnswerResultsLimit = 0 .. 50 @@ -76,6 +80,7 @@ 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" @@ -181,6 +186,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/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 +) From 457cadf26550e3d5da4411777d2c01eace0b6201 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 15:56:04 +0800 Subject: [PATCH 04/16] add PollUpdate --- CHANGELOG.md | 1 + .../TelegramBotAPI/types/update/PollUpdate.kt | 10 ++++++++++ .../TelegramBotAPI/types/update/RawUpdate.kt | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/update/PollUpdate.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e08a5c3e5..f2f24a1176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Type `PollOption` and `AnonymousPollOption` added * Type `Poll` added +* Type `PollUpdate` added and implemented in `RawUpdate`. Now `PollUpdate` can be retrieved from `RawUpdate` ## 0.12.0 Webhooks 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") } } From e2267c1cb4a0d34b566e351b10274ab104b7f19c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 16:04:02 +0800 Subject: [PATCH 05/16] add PollContent --- CHANGELOG.md | 1 + .../types/message/RawMessage.kt | 3 +++ .../types/message/content/PollContent.kt | 25 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index f2f24a1176..0c75627cac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * 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` ## 0.12.0 Webhooks 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..487f51ec33 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 @@ -17,6 +17,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 @@ -59,6 +60,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,6 +124,7 @@ data class RawMessage( contact != null -> ContactContent(contact) location != null -> LocationContent(location) venue != null -> VenueContent(venue) + poll != null -> PollContent(poll) else -> null } } 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..3000ead6de --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt @@ -0,0 +1,25 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.content + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.* +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 +import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlTexts +import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownTexts + +data class PollContent( + val poll: Poll +) : MessageContent { + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + replyToMessageId: MessageIdentifier?, + replyMarkup: KeyboardMarkup? + ): Request = TODO() +} From d7bbb6dd85556fa3bf6fd7003f9d7d94dadbd40e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 16:16:13 +0800 Subject: [PATCH 06/16] add SendPoll --- CHANGELOG.md | 3 +- .../TelegramBotAPI/requests/send/SendPoll.kt | 43 +++++++++++++++++++ .../TelegramBotAPI/types/Common.kt | 1 + .../types/message/content/PollContent.kt | 10 ++++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c75627cac..ada3fda1ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ * 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` +* Type `PollContent` added - now it can be a value of `ContentMessage#content` +* Request `SendPoll` added and `PollContent#createResend` now use it ## 0.12.0 Webhooks 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..8b03cfbb50 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt @@ -0,0 +1,43 @@ +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 + +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 pollQuectionTextLength) { + throw IllegalArgumentException("The length of questions for polls must be in $pollQuectionTextLength 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/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index dc44fd8778..2067e9bb3a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -32,6 +32,7 @@ val invoicePayloadBytesLimit = 1 until 128 val pollOptionTextLength = 1 .. 100 val pollQuectionTextLength = 1 until 256 +val pollOptionsLimit = 2 .. 10 val livePeriodLimit = 60 .. 86400 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 index 3000ead6de..ee88d4b3a2 100644 --- 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 @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier @@ -21,5 +22,12 @@ data class PollContent( disableNotification: Boolean, replyToMessageId: MessageIdentifier?, replyMarkup: KeyboardMarkup? - ): Request = TODO() + ): Request = SendPoll( + chatId, + poll.question, + poll.options.map { it.text }, + disableNotification, + replyToMessageId, + replyMarkup + ) } From 3bb1cb1552f6c33b723174efc9ee4e2e0fc76338 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 16:45:20 +0800 Subject: [PATCH 07/16] StopPoll and deprecations of By*MessageId --- CHANGELOG.md | 5 ++++ .../types/ByInlineMessageId.kt | 10 ++++---- .../CommonAbstracts/types/ByMessageId.kt | 9 +++---- .../types/InlineMessageAction.kt | 7 ++++++ .../CommonAbstracts/types/MessageAction.kt | 7 ++++++ .../TelegramBotAPI/requests/DeleteMessage.kt | 7 +++--- .../TelegramBotAPI/requests/ForwardMessage.kt | 9 +++++-- .../TelegramBotAPI/requests/StopPoll.kt | 24 +++++++++++++++++++ .../requests/chat/modify/PinChatMessage.kt | 7 +++--- .../edit/abstracts/EditChatMessage.kt | 6 ++--- .../requests/games/GetGameHighScoresByChat.kt | 4 ++-- .../GetGameHighScoresByInlineMessageId.kt | 3 ++- .../requests/games/SetGameScoreByChatId.kt | 4 ++-- .../games/SetGameScoreByInlineMessageId.kt | 3 ++- .../types/message/content/PollContent.kt | 5 ---- 15 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/InlineMessageAction.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/types/MessageAction.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ada3fda1ae..70935e43c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ * 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 ## 0.12.0 Webhooks 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..747dd7dc51 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt @@ -0,0 +1,24 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendChatMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +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..06ed944e1d 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,9 @@ 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..846b54e867 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,7 @@ 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 +13,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..78ff999c21 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,7 @@ 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 +19,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/types/message/content/PollContent.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/PollContent.kt index ee88d4b3a2..e6eef2fdff 100644 --- 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 @@ -1,18 +1,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request -import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.* 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 -import com.github.insanusmokrassar.TelegramBotAPI.utils.toHtmlTexts -import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownTexts data class PollContent( val poll: Poll From 8b67f16da3eb05f5af96001764e1df9c75abfe7f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 17:03:35 +0800 Subject: [PATCH 08/16] all PublicChat implementations may have pinned message, chats abstractions refactoring --- CHANGELOG.md | 3 +++ .../TelegramBotAPI/types/chat/ChannelChat.kt | 10 ++++++---- .../TelegramBotAPI/types/chat/Chat.kt | 12 ++++++------ .../TelegramBotAPI/types/chat/GroupChat.kt | 18 ++++++------------ .../TelegramBotAPI/types/chat/GroupChatImpl.kt | 15 +++++++++++++++ .../TelegramBotAPI/types/chat/PrivateChat.kt | 6 ++++-- .../TelegramBotAPI/types/chat/PublicChat.kt | 11 +++++++---- .../TelegramBotAPI/types/chat/RawChat.kt | 1 + .../types/chat/SupergroupChat.kt | 10 ++++++---- .../types/chat/abstracts/Chat.kt | 9 +++++++++ .../types/chat/abstracts/DescriptionChat.kt | 5 +++++ .../types/chat/abstracts/GroupChat.kt | 5 +++++ .../types/chat/abstracts/PublicChat.kt | 9 +++++++++ .../types/chat/abstracts/UsernameChat.kt | 7 +++++++ .../types/message/ChannelMediaGroupMessage.kt | 2 +- .../types/message/ChannelMessage.kt | 2 +- .../types/message/CommonMediaGroupMessage.kt | 2 +- .../types/message/CommonMessageImpl.kt | 2 +- .../types/message/ForwardedMessage.kt | 2 +- .../types/message/GroupEventMessage.kt | 2 +- .../TelegramBotAPI/types/message/RawMessage.kt | 1 + .../types/message/abstracts/Message.kt | 2 +- .../TelegramBotAPI/utils/MediaGroupList.kt | 2 +- 23 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/UsernameChat.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 70935e43c3..11a842d4dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ * 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 ## 0.12.0 Webhooks 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..4af0055df8 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,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 sealed class ForwardedMessage { abstract val messageId: MessageIdentifier 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 487f51ec33..da459a333b 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.* 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/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 From 2b831a803a2f33a6bb887c38c37dcba9b3d58e3d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 17:10:20 +0800 Subject: [PATCH 09/16] is_member adding --- CHANGELOG.md | 1 + .../TelegramBotAPI/types/ChatMember/RawChatMember.kt | 3 +++ .../TelegramBotAPI/types/ChatMember/RestrictedChatMember.kt | 1 + .../com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt | 1 + 4 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a842d4dc..baf5c4523d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ by their parents * 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` ## 0.12.0 Webhooks 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 2067e9bb3a..0c78643128 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -131,6 +131,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" From ba368e9fa432b4ac869c5ae8cb6cc227c40f9f09 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 17:26:02 +0800 Subject: [PATCH 10/16] AnonymousForwardedMessage --- CHANGELOG.md | 2 ++ .../TelegramBotAPI/types/Common.kt | 1 + .../types/message/ForwardedMessage.kt | 14 +++++++++++--- .../TelegramBotAPI/types/message/RawMessage.kt | 10 ++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baf5c4523d..1a14abb39f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ by their parents `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 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 0c78643128..aaa6bddd33 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 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 4af0055df8..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 @@ -4,8 +4,16 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* 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/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index da459a333b..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 @@ -37,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, @@ -132,8 +133,9 @@ data class RawMessage( @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, @@ -146,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 ) } } From d2a2c7a02fa3e6b87522bc63d1fee40bd8910afc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 17:28:07 +0800 Subject: [PATCH 11/16] optimize imports --- .../insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt | 6 ++---- .../requests/edit/abstracts/EditChatMessage.kt | 2 -- .../requests/games/GetGameHighScoresByInlineMessageId.kt | 1 - .../requests/games/SetGameScoreByInlineMessageId.kt | 1 - .../TelegramBotAPI/types/InputMedia/InputMediaAnimation.kt | 3 ++- .../TelegramBotAPI/types/InputMedia/InputMediaDocument.kt | 3 ++- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt index 747dd7dc51..8f5a4118f0 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/StopPoll.kt @@ -1,12 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests -import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.* +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.requests.send.abstracts.SendChatMessageRequest -import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup -import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll import kotlinx.serialization.* 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 06ed944e1d..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 @@ -2,8 +2,6 @@ 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, 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 846b54e867..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,5 @@ 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.* 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 78ff999c21..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,5 @@ 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.* 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( From 68affb7dc7af132eb92d7ca5bd511569affa9c59 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 18:46:55 +0800 Subject: [PATCH 12/16] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index a26b2cde92..6c9bdccdb9 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)). 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? From 527ee306fcc2a0f23fdea225c2633ac0de5f2485 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 18:47:39 +0800 Subject: [PATCH 13/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c9bdccdb9..37b4ed1e7a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ solves or unuseful moments are describing by official [Telegram Bot API](https:/ ## Compatibility -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)). It will be implemented 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? From 6b045549f9af1f9dfd1295d6c76a476c34856c7f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 19:22:18 +0800 Subject: [PATCH 14/16] fix pollQuestionTextLength name --- .../insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt | 4 ++-- .../github/insanusmokrassar/TelegramBotAPI/types/Common.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 index 8b03cfbb50..ee244f2788 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt @@ -25,8 +25,8 @@ data class SendPoll( ReplyingMarkupSendMessageRequest { init { - if (question.length !in pollQuectionTextLength) { - throw IllegalArgumentException("The length of questions for polls must be in $pollQuectionTextLength range, but was ${question.length}") + 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) { 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 aaa6bddd33..9122be4efe 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -32,7 +32,7 @@ val invoiceDescriptionLimit = 1 until 256 val invoicePayloadBytesLimit = 1 until 128 val pollOptionTextLength = 1 .. 100 -val pollQuectionTextLength = 1 until 256 +val pollQuestionTextLength = 1 until 256 val pollOptionsLimit = 2 .. 10 val livePeriodLimit = 60 .. 86400 From c4500177644f37f7e5d24c6b81d7b580cb8ef5f4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Apr 2019 19:40:41 +0800 Subject: [PATCH 15/16] change SendPoll to be serializable --- .../insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt | 2 ++ 1 file changed, 2 insertions(+) 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 index ee244f2788..8a9eee0b57 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt @@ -7,7 +7,9 @@ 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, From 60d420f775d3afb800a3ff3a6cb0ed158143d1d8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Apr 2019 10:23:08 +0800 Subject: [PATCH 16/16] rename file of PollOption and remove redundant abstract folder in polls type --- .../types/polls/{AnonymousPollOption.kt => PollOption.kt} | 0 .../TelegramBotAPI/types/polls/abstracts/PollOption.kt | 2 -- 2 files changed, 2 deletions(-) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/{AnonymousPollOption.kt => PollOption.kt} (100%) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt similarity index 100% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/AnonymousPollOption.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/PollOption.kt diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt deleted file mode 100644 index 2d18915931..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/polls/abstracts/PollOption.kt +++ /dev/null @@ -1,2 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.polls.abstracts -