From 84d2c88032e2168e4d1513087daf45eaf929ab1e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:16:04 +0600 Subject: [PATCH 01/20] started 0.25.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9334f267..3e32db9d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ * `FlowsUpdatesFilter` now have two additional flows: `pollAnswerFlow`, `unknownUpdateTypeFlow` * `ExtendedUser` (`typealias`) was added as a `PreviewFeature` +### 0.25.2 + ### 0.25.1 * Update kotlin: `1.3.70` -> `1.3.71` diff --git a/gradle.properties b/gradle.properties index 87bf45babc..94d5361560 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ uuid_version=0.1.0 ktor_version=1.3.2 library_group=com.github.insanusmokrassar -library_version=0.25.1 +library_version=0.25.2 gradle_bintray_plugin_version=1.8.4 From c3fca5c6c47a4d1843ba93b13d3eada8be22c2ab Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:30:22 +0600 Subject: [PATCH 02/20] include dice in TelegramBotAPI --- CHANGELOG.md | 5 +++ .../TelegramBotAPI/requests/send/SendDice.kt | 34 +++++++++++++++++++ .../TelegramBotAPI/types/Common.kt | 4 +++ .../TelegramBotAPI/types/Dice.kt | 10 ++++++ .../types/message/RawMessage.kt | 2 ++ .../types/message/content/DiceContent.kt | 20 +++++++++++ 6 files changed, 75 insertions(+) create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e32db9d5e..7ba140caa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,11 @@ ### 0.25.2 +* `TelegramBotAPI`: + * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) + * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) + * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) + ### 0.25.1 * Update kotlin: `1.3.70` -> `1.3.71` diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt new file mode 100644 index 0000000000..a6537de89d --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt @@ -0,0 +1,34 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.send + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableNotification +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMessageId +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.DiceContent +import kotlinx.serialization.* + +internal val DiceContentMessageResultDeserializer: DeserializationStrategy> + = TelegramBotAPIMessageDeserializationStrategyClass() + +@Serializable +data class SendDice( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(disableNotificationField) + override val disableNotification: Boolean = false, + @SerialName(replyToMessageIdField) + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(replyMarkupField) + override val replyMarkup: KeyboardMarkup? = null +) : ReplyingMarkupSendMessageRequest>, ReplyMessageId, DisableNotification { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "sendDice" + + override val resultDeserializer: DeserializationStrategy> + get() = DiceContentMessageResultDeserializer +} \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index f460b7b9e8..0f0c9647bd 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -19,6 +19,7 @@ typealias InlineMessageIdentifier = String typealias PollIdentifier = String typealias StickerSetName = String typealias FileUniqueId = String +typealias DiceResult = Int typealias Seconds = Int @@ -45,6 +46,8 @@ val inlineQueryAnswerResultsLimit = 0 .. 50 val customTitleLength = 0 .. 16 +val diceResultLimit = 1 .. 6 + const val chatIdField = "chat_id" const val messageIdField = "message_id" const val updateIdField = "update_id" @@ -230,6 +233,7 @@ const val optionsField = "options" const val payField = "pay" const val permissionsField = "permissions" const val typeField = "type" +const val valueField = "value" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt new file mode 100644 index 0000000000..00dd3f28ca --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class Dice( + @SerialName(valueField) + val value: DiceResult +) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 8e4ff44663..99a0fa25bb 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -74,6 +74,7 @@ internal data class RawMessage( private val migrate_from_chat_id: ChatIdentifier? = null, private val pinned_message: RawMessage? = null, private val invoice: Invoice? = null, + private val dice: Dice? = null, private val successful_payment: SuccessfulPayment? = null, // login property @@ -123,6 +124,7 @@ internal data class RawMessage( adaptedCaptionEntities ) sticker != null -> StickerContent(sticker) + dice != null -> DiceContent(dice) game != null -> GameContent(game.asGame) video_note != null -> VideoNoteContent(video_note) contact != null -> ContactContent(contact) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt new file mode 100644 index 0000000000..94446bd65b --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt @@ -0,0 +1,20 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.content + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent + +data class DiceContent( + val dice: Dice +) : MessageContent { + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + replyToMessageId: MessageIdentifier?, + replyMarkup: KeyboardMarkup? + ): Request> { + TODO("Not yet implemented") + } +} From 8ef7acab2dea8374c1c1e963c8aa70b28fc14d67 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:33:17 +0600 Subject: [PATCH 03/20] sendDice in extensions api --- CHANGELOG.md | 2 ++ .../extensions/api/send/SendDice.kt | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ba140caa0..c323f89e82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) +* `TelegramBotAPI-extensions-api`: + * Extensions `sendDice` was added ### 0.25.1 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt new file mode 100644 index 0000000000..c0e7f89442 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt @@ -0,0 +1,24 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendDice +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.chat.abstracts.Chat + +suspend fun RequestsExecutor.sendDice( + chatId: ChatIdentifier, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendDice(chatId, disableNotification, replyToMessageId, replyMarkup) +) + +suspend fun RequestsExecutor.sendDice( + chat: Chat, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDice(chat.id, disableNotification, replyToMessageId, replyMarkup) From 1d3736c44e2c2465e681624f9a601e08e88a3283 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:37:30 +0600 Subject: [PATCH 04/20] add realisation of DiceContent#createResend --- .../TelegramBotAPI/types/message/content/DiceContent.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt index 94446bd65b..cafd35d3b8 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendDice import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage @@ -14,7 +15,5 @@ data class DiceContent( disableNotification: Boolean, replyToMessageId: MessageIdentifier?, replyMarkup: KeyboardMarkup? - ): Request> { - TODO("Not yet implemented") - } + ): Request> = SendDice(chatId, disableNotification, replyToMessageId, replyMarkup) } From 54589ed17b949d9b410a3b2565fd3424bae99cab Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:40:36 +0600 Subject: [PATCH 05/20] BotCommand --- CHANGELOG.md | 1 + .../TelegramBotAPI/types/BotCommand.kt | 12 ++++++++++++ .../insanusmokrassar/TelegramBotAPI/types/Common.kt | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c323f89e82..2b17fa808e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) + * `BotCommand` was added * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt new file mode 100644 index 0000000000..1e3e9ee01d --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt @@ -0,0 +1,12 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class BotCommand( + @SerialName(botCommandField) + val command: String, + @SerialName(descriptionField) + val description: String +) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 0f0c9647bd..bfff406189 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -48,6 +48,9 @@ val customTitleLength = 0 .. 16 val diceResultLimit = 1 .. 6 +val botCommandLimit = 1 .. 32 +val botCommandDescriptionLimit = 3 .. 256 + const val chatIdField = "chat_id" const val messageIdField = "message_id" const val updateIdField = "update_id" @@ -167,6 +170,7 @@ const val thumbHeightField = "thumb_height" const val inputMessageContentField = "input_message_content" const val hideUrlField = "hide_url" +const val botCommandField = "command" const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" From ec70813e499a9081ffea1d00b6144f1409a8cb9b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:52:00 +0600 Subject: [PATCH 06/20] commands handling added --- CHANGELOG.md | 7 ++++++ .../TelegramBotAPI/extensions/api/GetMe.kt | 8 ++++-- .../extensions/api/bot/GetMe.kt | 6 +++++ .../extensions/api/bot/GetMyCommands.kt | 6 +++++ .../extensions/api/bot/SetMyCommands.kt | 10 ++++++++ .../TelegramBotAPI/requests/GetMe.kt | 19 ++++++-------- .../TelegramBotAPI/requests/bot/GetMe.kt | 14 +++++++++++ .../requests/bot/GetMyCommands.kt | 17 +++++++++++++ .../requests/bot/SetMyCommands.kt | 25 +++++++++++++++++++ .../TelegramBotAPI/types/Common.kt | 2 ++ 10 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b17fa808e..9bc7cee0f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,8 +32,15 @@ * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) * `BotCommand` was added + * `GetMyCommands` request was added + * `SetMyCommands` request was added + * `GetMe` now is object instead of class + * `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe` * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added + * Extension `getMyCommands` request was added + * Extension `setMyCommands` request was added + * Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe` ### 0.25.1 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt index d0a48bdbf4..889d07a6b0 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt @@ -1,6 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.GetMe +import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.getMe -suspend fun RequestsExecutor.getMe() = execute(GetMe()) \ No newline at end of file +@Deprecated( + "Replaced", + ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe") +) +suspend fun RequestsExecutor.getMe() = getMe() \ No newline at end of file diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt new file mode 100644 index 0000000000..66d9b4512d --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe + +suspend fun RequestsExecutor.getMe() = execute(GetMe) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt new file mode 100644 index 0000000000..41a9bef0f7 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands + +suspend fun RequestsExecutor.getMyCommands() = execute(GetMyCommands) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt new file mode 100644 index 0000000000..d8da9a63bf --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands +import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand + +suspend fun RequestsExecutor.setMyCommands( + commands: List +) = execute(SetMyCommands(commands)) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt index b0cd428c8c..4c4dab284b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt @@ -1,14 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests -import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest -import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot -import kotlinx.serialization.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe -@Serializable -class GetMe : SimpleRequest { - override fun method(): String = "getMe" - override val resultDeserializer: DeserializationStrategy - get() = ExtendedBot.serializer() - override val requestSerializer: SerializationStrategy<*> - get() = serializer() -} +@Deprecated( + "Replaced", + ReplaceWith( + "GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe" + ) +) +typealias GetMe = GetMe diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt new file mode 100644 index 0000000000..b200c34dbd --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt @@ -0,0 +1,14 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot +import kotlinx.serialization.* + +@Serializable +object GetMe : SimpleRequest { + override fun method(): String = "getMe" + override val resultDeserializer: DeserializationStrategy + get() = ExtendedBot.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt new file mode 100644 index 0000000000..a7a3c764bb --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand +import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer + +private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer()) + +@Serializable +object GetMyCommands : SimpleRequest> { + override fun method(): String = "getMyCommands" + override val resultDeserializer: DeserializationStrategy> + get() = getMyCommandsSerializer + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt new file mode 100644 index 0000000000..a5dbfd2dc0 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt @@ -0,0 +1,25 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.builtins.serializer + +@Serializable +class SetMyCommands( + @SerialName(botCommandsField) + val commands: List +) : SimpleRequest { + override fun method(): String = "getMyCommands" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + init { + if (commands.size !in botCommandsLimit) { + error("Bot commands list size able to be in range $botCommandsLimit, but incoming size is ${commands.size}") + } + } +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index bfff406189..f5cfb8ae78 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -50,6 +50,7 @@ val diceResultLimit = 1 .. 6 val botCommandLimit = 1 .. 32 val botCommandDescriptionLimit = 3 .. 256 +val botCommandsLimit = 0 .. 100 const val chatIdField = "chat_id" const val messageIdField = "message_id" @@ -171,6 +172,7 @@ const val inputMessageContentField = "input_message_content" const val hideUrlField = "hide_url" const val botCommandField = "command" +const val botCommandsField = "commands" const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" From 53257ff131fd89fed3cb616eee675c8f3b5a623a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 21:53:36 +0600 Subject: [PATCH 07/20] hotfix for setMyCommands request --- .../TelegramBotAPI/requests/bot/SetMyCommands.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt index a5dbfd2dc0..1b2e262511 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt @@ -11,7 +11,7 @@ class SetMyCommands( @SerialName(botCommandsField) val commands: List ) : SimpleRequest { - override fun method(): String = "getMyCommands" + override fun method(): String = "setMyCommands" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() override val requestSerializer: SerializationStrategy<*> From f6692a22d16a53ebb2466f5b3a7cf68109d2f312 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:03:59 +0600 Subject: [PATCH 08/20] create new animated sticker set --- CHANGELOG.md | 4 ++ .../stickers/CreateNewAnimatedStickerSet.kt | 54 +++++++++++++++ ...kerSet.kt => CreateNewStaticStickerSet.kt} | 18 ++--- ...rSet.kt => CreateNewAnimatedStickerSet.kt} | 8 +-- .../stickers/CreateNewStaticStickerSet.kt | 68 +++++++++++++++++++ .../TelegramBotAPI/types/Common.kt | 1 + 6 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt rename TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/{CreateNewStickerSet.kt => CreateNewStaticStickerSet.kt} (73%) rename TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/{CreateNewStickerSet.kt => CreateNewAnimatedStickerSet.kt} (86%) create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc7cee0f0..817c2acc09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,11 +36,15 @@ * `SetMyCommands` request was added * `GetMe` now is object instead of class * `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe` + * `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet` + * `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`) * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added * Extension `setMyCommands` request was added * Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe` + * **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`** + * Extensions `createNewAnimatedStickerSet` was added ### 0.25.1 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt new file mode 100644 index 0000000000..f1d2e14de0 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt @@ -0,0 +1,54 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewAnimatedStickerSet +import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser +import com.github.insanusmokrassar.TelegramBotAPI.types.UserId +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + userId: UserId, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + userId: UserId, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + user: CommonUser, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewAnimatedStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + user: CommonUser, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewAnimatedStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt similarity index 73% rename from TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt rename to TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt index b65acc0f0a..9234137195 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt @@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStickerSet +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( userId: UserId, name: String, sticker: FileId, @@ -16,10 +16,10 @@ suspend fun RequestsExecutor.createNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = execute( - CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( userId: UserId, name: String, sticker: MultipartFile, @@ -27,28 +27,28 @@ suspend fun RequestsExecutor.createNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = execute( - CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( user: CommonUser, name: String, sticker: FileId, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null -) = createNewStickerSet( +) = createNewStaticStickerSet( user.id, name, sticker, emojis, containsMasks, maskPosition ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( user: CommonUser, name: String, sticker: MultipartFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null -) = createNewStickerSet( +) = createNewStaticStickerSet( user.id, name, sticker, emojis, containsMasks, maskPosition ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt similarity index 86% rename from TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt rename to TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt index b02b967fc3..93596c6b06 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* -fun CreateNewStickerSet( +fun CreateNewAnimatedStickerSet( userId: UserId, name: String, sticker: InputFile, @@ -15,7 +15,7 @@ fun CreateNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ): Request { - val data = CreateNewStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + val data = CreateNewAnimatedStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -26,14 +26,14 @@ fun CreateNewStickerSet( } @Serializable -data class CreateNewStickerSet internal constructor( +data class CreateNewAnimatedStickerSet internal constructor( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) override val name: String, @SerialName(emojisField) override val emojis: String, - @SerialName(pngStickerField) + @SerialName(tgsStickerField) val sticker: FileId? = null, @SerialName(containsMasksField) val containsMasks: Boolean? = null, diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt new file mode 100644 index 0000000000..88f448b5f0 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt @@ -0,0 +1,68 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import kotlinx.serialization.* + +fun CreateNewStaticStickerSet( + userId: UserId, + name: String, + sticker: InputFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +): Request { + val data = CreateNewStaticStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +fun CreateNewStickerSet( + userId: UserId, + name: String, + sticker: InputFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +): Request = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + +@Deprecated( + "Renamed", + ReplaceWith("CreateNewStaticStickerSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet") +) +typealias CreateNewStickerSet = CreateNewStaticStickerSet + +@Serializable +data class CreateNewStaticStickerSet internal constructor( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(emojisField) + override val emojis: String, + @SerialName(pngStickerField) + val sticker: FileId? = null, + @SerialName(containsMasksField) + val containsMasks: Boolean? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null +) : StickerSetAction { + init { + if(emojis.isEmpty()) { + throw IllegalArgumentException("Emojis must not be empty") + } + } + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "createNewStickerSet" +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index f5cfb8ae78..1b5ba30e63 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -192,6 +192,7 @@ const val canRestrictMembersField = "can_restrict_members" const val canPinMessagesField = "can_pin_messages" const val canPromoteMembersField = "can_promote_members" const val pngStickerField = "png_sticker" +const val tgsStickerField = "tgs_sticker" const val okField = "ok" const val captionField = "caption" From e60630b331af2405b9ac556385c1a37416af1a8b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:07:13 +0600 Subject: [PATCH 09/20] add StickerSet#thumb --- CHANGELOG.md | 1 + .../TelegramBotAPI/types/stickers/StickerSet.kt | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 817c2acc09..ed749f5b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ * `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe` * `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet` * `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`) + * `StickerSet#thumb` was added * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt index b36fbc4016..bee7cfad1c 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.stickers import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,5 +17,7 @@ data class StickerSet( @SerialName(isAnimatedField) val isAnimated: Boolean = false, @SerialName(containsMasksField) - val containsMasks: Boolean = false + val containsMasks: Boolean = false, + @SerialName(thumbField) + val thumb: PhotoSize? = null ) From 274afe8efc016b909315ebc9329b9eea31f0b2cc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:12:31 +0600 Subject: [PATCH 10/20] addAnimatedStickerToSet --- CHANGELOG.md | 4 + .../api/stickers/AddAnimatedStickerToSet.kt | 90 +++++++++++++++++++ ...ickerToSet.kt => AddStaticStickerToSet.kt} | 34 +++---- ...kerToSet.kt => AddAnimatedStickerToSet.kt} | 9 +- .../stickers/AddStaticStickerToSet.kt | 67 ++++++++++++++ 5 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt rename TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/{AddStickerToSet.kt => AddStaticStickerToSet.kt} (73%) rename TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/{AddStickerToSet.kt => AddAnimatedStickerToSet.kt} (86%) create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index ed749f5b6a..e7322f3483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ * `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet` * `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`) * `StickerSet#thumb` was added + * `AddStickerToSet` renamed to `AddStaticStickerToSet` + * `AddAnimatedStickerToSet` request was added * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added @@ -46,6 +48,8 @@ * Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe` * **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`** * Extensions `createNewAnimatedStickerSet` was added + * **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`** + * Extensions `addAnimatedStickerToSet` was added ### 0.25.1 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt new file mode 100644 index 0000000000..f9d32b0727 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt @@ -0,0 +1,90 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddAnimatedStickerToSet +import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser +import com.github.insanusmokrassar.TelegramBotAPI.types.UserId +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt similarity index 73% rename from TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt rename to TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt index e2436eb245..2d09222784 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt @@ -3,88 +3,88 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStickerToSet +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSetName: String, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null ) = execute( - AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSetName: String, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null ) = execute( - AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSetName: String, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSetName, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSetName: String, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSetName, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSet: StickerSet, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( userId, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSet: StickerSet, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( userId, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSet: StickerSet, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSet: StickerSet, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSet.name, sticker, emojis, maskPosition ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt similarity index 86% rename from TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt rename to TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt index 113ad5966e..41467aaf73 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt @@ -6,15 +6,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.St import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* - -fun AddStickerToSet( +fun AddAnimatedStickerToSet( userId: UserId, stickerSetName: String, sticker: InputFile, emojis: String, maskPosition: MaskPosition? = null ): Request { - val data = AddStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) + val data = AddAnimatedStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -25,14 +24,14 @@ fun AddStickerToSet( } @Serializable -data class AddStickerToSet internal constructor( +data class AddAnimatedStickerToSet internal constructor( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) override val name: String, @SerialName(emojisField) override val emojis: String, - @SerialName(pngStickerField) + @SerialName(tgsStickerField) val sticker: FileId? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt new file mode 100644 index 0000000000..9cf48bcd02 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt @@ -0,0 +1,67 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import kotlinx.serialization.* +fun AddStaticStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: InputFile, + emojis: String, + maskPosition: MaskPosition? = null +): Request { + val data = AddStaticStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +@Deprecated( + "Renamed", + ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") +) +fun AddStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: InputFile, + emojis: String, + maskPosition: MaskPosition? = null +) = AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + +@Deprecated( + "Renamed", + ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") +) +typealias AddStickerToSet = AddStaticStickerToSet + +@Serializable +data class AddStaticStickerToSet internal constructor( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(emojisField) + override val emojis: String, + @SerialName(pngStickerField) + val sticker: FileId? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null +) : StickerSetAction { + init { + if(emojis.isEmpty()) { + throw IllegalArgumentException("Emojis must not be empty") + } + } + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "addStickerToSet" +} From 033ec8f2da1e86eb88ff841cf4cce1a75f32fed8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:18:59 +0600 Subject: [PATCH 11/20] update version --- CHANGELOG.md | 52 +++++++++++++++++++++++------------------------ gradle.properties | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7322f3483..615decaf10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # TelegramBotAPI changelog +## 0.26.0 + +* `TelegramBotAPI`: + * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) + * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) + * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) + * `BotCommand` was added + * `GetMyCommands` request was added + * `SetMyCommands` request was added + * `GetMe` now is object instead of class + * `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe` + * `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet` + * `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`) + * `StickerSet#thumb` was added + * `AddStickerToSet` renamed to `AddStaticStickerToSet` + * `AddAnimatedStickerToSet` request was added +* `TelegramBotAPI-extensions-api`: + * Extensions `sendDice` was added + * Extension `getMyCommands` request was added + * Extension `setMyCommands` request was added + * Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe` + * **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`** + * Extensions `createNewAnimatedStickerSet` was added + * **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`** + * Extensions `addAnimatedStickerToSet` was added + ## 0.25.0 * Common: @@ -25,32 +51,6 @@ * `FlowsUpdatesFilter` now have two additional flows: `pollAnswerFlow`, `unknownUpdateTypeFlow` * `ExtendedUser` (`typealias`) was added as a `PreviewFeature` -### 0.25.2 - -* `TelegramBotAPI`: - * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) - * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) - * Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object) - * `BotCommand` was added - * `GetMyCommands` request was added - * `SetMyCommands` request was added - * `GetMe` now is object instead of class - * `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe` - * `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet` - * `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`) - * `StickerSet#thumb` was added - * `AddStickerToSet` renamed to `AddStaticStickerToSet` - * `AddAnimatedStickerToSet` request was added -* `TelegramBotAPI-extensions-api`: - * Extensions `sendDice` was added - * Extension `getMyCommands` request was added - * Extension `setMyCommands` request was added - * Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe` - * **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`** - * Extensions `createNewAnimatedStickerSet` was added - * **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`** - * Extensions `addAnimatedStickerToSet` was added - ### 0.25.1 * Update kotlin: `1.3.70` -> `1.3.71` diff --git a/gradle.properties b/gradle.properties index 94d5361560..c84053e095 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ uuid_version=0.1.0 ktor_version=1.3.2 library_group=com.github.insanusmokrassar -library_version=0.25.2 +library_version=0.26.0 gradle_bintray_plugin_version=1.8.4 From 9cd2a6220c3b0b190e6c0871cf33646968891162 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:29:34 +0600 Subject: [PATCH 12/20] add setStickerSetThumb --- CHANGELOG.md | 2 + .../api/stickers/SetStickerSetThumb.kt | 74 +++++++++++++++++++ .../stickers/AddAnimatedStickerToSet.kt | 3 +- .../stickers/AddStaticStickerToSet.kt | 4 +- .../stickers/CreateNewAnimatedStickerSet.kt | 3 +- .../stickers/CreateNewStaticStickerSet.kt | 3 +- .../requests/stickers/SetStickerSetThumb.kt | 37 ++++++++++ .../abstracts/StandardStickerSetAction.kt | 8 ++ .../stickers/abstracts/StickerSetAction.kt | 2 - 9 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt create mode 100644 TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 615decaf10..ee25647e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * `StickerSet#thumb` was added * `AddStickerToSet` renamed to `AddStaticStickerToSet` * `AddAnimatedStickerToSet` request was added + * `SetStickerSetThumb` request was added * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added @@ -25,6 +26,7 @@ * Extensions `createNewAnimatedStickerSet` was added * **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`** * Extensions `addAnimatedStickerToSet` was added + * Extensions `setStickerSetThumb` was added ## 0.25.0 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt new file mode 100644 index 0000000000..e70c8a36da --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt @@ -0,0 +1,74 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.SetStickerSetThumb +import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser +import com.github.insanusmokrassar.TelegramBotAPI.types.UserId +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet + +suspend fun RequestsExecutor.setStickerSetThumb( + userId: UserId, + stickerSetName: String, + sticker: FileId +) = execute( + SetStickerSetThumb(userId, stickerSetName, sticker) +) + +suspend fun RequestsExecutor.setStickerSetThumb( + userId: UserId, + stickerSetName: String, + sticker: MultipartFile +) = execute( + SetStickerSetThumb(userId, stickerSetName, sticker) +) + +suspend fun RequestsExecutor.setStickerSetThumb( + user: CommonUser, + stickerSetName: String, + sticker: FileId +) = setStickerSetThumb( + user.id, stickerSetName, sticker +) + +suspend fun RequestsExecutor.setStickerSetThumb( + user: CommonUser, + stickerSetName: String, + sticker: MultipartFile +) = setStickerSetThumb( + user.id, stickerSetName, sticker +) + +suspend fun RequestsExecutor.setStickerSetThumb( + userId: UserId, + stickerSet: StickerSet, + sticker: FileId +) = setStickerSetThumb( + userId, stickerSet.name, sticker +) + +suspend fun RequestsExecutor.setStickerSetThumb( + userId: UserId, + stickerSet: StickerSet, + sticker: MultipartFile +) = setStickerSetThumb( + userId, stickerSet.name, sticker +) + +suspend fun RequestsExecutor.setStickerSetThumb( + user: CommonUser, + stickerSet: StickerSet, + sticker: FileId +) = setStickerSetThumb( + user.id, stickerSet.name, sticker +) + +suspend fun RequestsExecutor.setStickerSetThumb( + user: CommonUser, + stickerSet: StickerSet, + sticker: MultipartFile +) = setStickerSetThumb( + user.id, stickerSet.name, sticker +) + diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt index 41467aaf73..b73c71d320 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition @@ -35,7 +36,7 @@ data class AddAnimatedStickerToSet internal constructor( val sticker: FileId? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt index 9cf48bcd02..ac92cb1f5c 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt @@ -2,10 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* + fun AddStaticStickerToSet( userId: UserId, stickerSetName: String, @@ -53,7 +55,7 @@ data class AddStaticStickerToSet internal constructor( val sticker: FileId? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt index 93596c6b06..800a3e1a6f 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition @@ -39,7 +40,7 @@ data class CreateNewAnimatedStickerSet internal constructor( val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt index 88f448b5f0..70ab9bd519 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt @@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition @@ -54,7 +55,7 @@ data class CreateNewStaticStickerSet internal constructor( val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt new file mode 100644 index 0000000000..411bb3d091 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt @@ -0,0 +1,37 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.* + +fun SetStickerSetThumb( + userId: UserId, + stickerSetName: String, + sticker: InputFile +): Request { + val data = SetStickerSetThumb(userId, stickerSetName, sticker as? FileId) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(thumbField to sticker) + ) + is FileId -> data + } +} + +@Serializable +data class SetStickerSetThumb internal constructor( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: StickerSetName, + @SerialName(thumbField) + val thumb: FileId? = null +) : StickerSetAction { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "setStickerSetThumb" +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt new file mode 100644 index 0000000000..a4720e4a6c --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt @@ -0,0 +1,8 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts + +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition + +interface StandardStickerSetAction : StickerSetAction { + val emojis: String // must be more than one + val maskPosition: MaskPosition? +} \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt index 7563fb0752..4336052d98 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt @@ -9,8 +9,6 @@ import kotlinx.serialization.builtins.serializer interface StickerSetAction : SimpleRequest { val userId: UserId val name: String - val emojis: String // must be more than one - val maskPosition: MaskPosition? override val resultDeserializer: KSerializer get() = Boolean.serializer() From 9c0106d229a6a9e8b25732ace332ba2d3419acdb Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:31:54 +0600 Subject: [PATCH 13/20] StickerSetAction -> StandardStickerSetAction --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee25647e4c..80049c9e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * `AddStickerToSet` renamed to `AddStaticStickerToSet` * `AddAnimatedStickerToSet` request was added * `SetStickerSetThumb` request was added + * Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction` * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added From 55ed3e165b3bed5696fe911c7fb6ba50e9fb2799 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:47:20 +0600 Subject: [PATCH 14/20] resolve compiling errors --- .../TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt index 411bb3d091..27bd63af34 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt @@ -7,8 +7,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* fun SetStickerSetThumb( - userId: UserId, stickerSetName: String, + userId: UserId, sticker: InputFile ): Request { val data = SetStickerSetThumb(userId, stickerSetName, sticker as? FileId) From 013944c5c955035499c3b43b7b50c1a8a84710fa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:52:57 +0600 Subject: [PATCH 15/20] real fix:) --- .../api/stickers/SetStickerSetThumb.kt | 50 +++++++++---------- .../requests/stickers/SetStickerSetThumb.kt | 18 +++---- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt index e70c8a36da..45fad6497a 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt @@ -1,4 +1,4 @@ -package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.thumbs import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId @@ -10,65 +10,65 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet suspend fun RequestsExecutor.setStickerSetThumb( userId: UserId, - stickerSetName: String, - sticker: FileId + thumbSetName: String, + thumb: FileId ) = execute( - SetStickerSetThumb(userId, stickerSetName, sticker) + SetStickerSetThumb(userId, thumbSetName, thumb) ) suspend fun RequestsExecutor.setStickerSetThumb( userId: UserId, - stickerSetName: String, - sticker: MultipartFile + thumbSetName: String, + thumb: MultipartFile ) = execute( - SetStickerSetThumb(userId, stickerSetName, sticker) + SetStickerSetThumb(userId, thumbSetName, thumb) ) suspend fun RequestsExecutor.setStickerSetThumb( user: CommonUser, - stickerSetName: String, - sticker: FileId + thumbSetName: String, + thumb: FileId ) = setStickerSetThumb( - user.id, stickerSetName, sticker + user.id, thumbSetName, thumb ) suspend fun RequestsExecutor.setStickerSetThumb( user: CommonUser, - stickerSetName: String, - sticker: MultipartFile + thumbSetName: String, + thumb: MultipartFile ) = setStickerSetThumb( - user.id, stickerSetName, sticker + user.id, thumbSetName, thumb ) suspend fun RequestsExecutor.setStickerSetThumb( userId: UserId, - stickerSet: StickerSet, - sticker: FileId + thumbSet: StickerSet, + thumb: FileId ) = setStickerSetThumb( - userId, stickerSet.name, sticker + userId, thumbSet.name, thumb ) suspend fun RequestsExecutor.setStickerSetThumb( userId: UserId, - stickerSet: StickerSet, - sticker: MultipartFile + thumbSet: StickerSet, + thumb: MultipartFile ) = setStickerSetThumb( - userId, stickerSet.name, sticker + userId, thumbSet.name, thumb ) suspend fun RequestsExecutor.setStickerSetThumb( user: CommonUser, - stickerSet: StickerSet, - sticker: FileId + thumbSet: StickerSet, + thumb: FileId ) = setStickerSetThumb( - user.id, stickerSet.name, sticker + user.id, thumbSet.name, thumb ) suspend fun RequestsExecutor.setStickerSetThumb( user: CommonUser, - stickerSet: StickerSet, - sticker: MultipartFile + thumbSet: StickerSet, + thumb: MultipartFile ) = setStickerSetThumb( - user.id, stickerSet.name, sticker + user.id, thumbSet.name, thumb ) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt index 27bd63af34..5f8cfe7186 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt @@ -7,22 +7,18 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* fun SetStickerSetThumb( - stickerSetName: String, userId: UserId, - sticker: InputFile + stickerSetName: String, + thumb: MultipartFile ): Request { - val data = SetStickerSetThumb(userId, stickerSetName, sticker as? FileId) - return when (sticker) { - is MultipartFile -> CommonMultipartFileRequest( - data, - mapOf(thumbField to sticker) - ) - is FileId -> data - } + return CommonMultipartFileRequest( + SetStickerSetThumb(userId, stickerSetName), + mapOf(thumbField to thumb) + ) } @Serializable -data class SetStickerSetThumb internal constructor( +data class SetStickerSetThumb ( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) From 7d85b6fb88871b9cd04ee5d5a4cc6f089d366ce8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 31 Mar 2020 11:00:22 +0600 Subject: [PATCH 16/20] update readme of telegram bot api --- TelegramBotAPI/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/TelegramBotAPI/README.md b/TelegramBotAPI/README.md index b93ed650f8..d255e585bf 100644 --- a/TelegramBotAPI/README.md +++ b/TelegramBotAPI/README.md @@ -12,11 +12,10 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [23th of January 2020 update of TelegramBotAPI (version 4.6)](https://core.telegram.org/bots/api#january-23-2020). -There is Telegram Passport API exception of implemented functionality, which was presented in +This version compatible with [30th of March 2020 update of TelegramBotAPI (version 4.7)](https://core.telegram.org/bots/api#march-30-2020). +There is only one exception of implemented functionality - Telegram Passport API, which was presented in [August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented -as soon as possible. All APIs that are not included are presented -[wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Not-included-API). +as soon as possible. ## How to implement library? From ee1f115d7715cb2639a61c1ff18cd89e4c0c27d1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 31 Mar 2020 11:11:37 +0600 Subject: [PATCH 17/20] refill TelegramBotAPI-extensions-api --- TelegramBotAPI-extensions-api/README.md | 48 +++++++++++++++++++------ 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/TelegramBotAPI-extensions-api/README.md b/TelegramBotAPI-extensions-api/README.md index 4162bcd5f9..275b475f9c 100644 --- a/TelegramBotAPI-extensions-api/README.md +++ b/TelegramBotAPI-extensions-api/README.md @@ -56,20 +56,46 @@ compile "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$telegrambota ## Example of usage and comparison with `TelegramBotAPI` -As said in [TelegramBotAPI](../TelegramBotAPI/README.md#Requests), it is possible to use next syntax for requests: +Here presented review table for comparison of api from original [TelegramBotAPI](../TelegramBotAPI/README.md#Requests) +and extensions-api library: -```kotlin -val requestsExecutor: RequestsExecutor = ... -requestsExecutor.execute(GetMe()) -``` - -This library offer a little bit another way for this: +In all examples supposed that you have created bot with next approximate lines: ```kotlin val bot: RequestsExecutor = ... -bot.getMe() ``` -The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt) -request is -[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt). +| TelegramBotAPI | TelegramBotAPI-extensions-api | +|----------------|-------------------------------| +| bot.execute(GetMe) | bot.getMe() | +| bot.execute(SendTextMessage(someChatId, text)) | bot.sendTextMessage(chat, text) | + +## Updates + +Usually, it is more comfortable to use filter object to get separated types of updates: + +```kotlin +val filter = FlowsUpdatesFilter(100) +``` + +In this case you will be able: + +* Separate types of incoming updates (even media groups) +* Simplify launch of getting updates: +```kotlin +bot.startGettingOfUpdates( + filter, + scope = CoroutineScope(Dispatchers.Default) +) +``` +* Use `filter` flows to comfortable filter, map and do other operations with the whole +getting updates process: +```kotlin +filter.messageFlow.mapNotNull { + it.data as? ContentMessage<*> +}.onEach { + println(it) +}.launchIn( + CoroutineScope(Dispatchers.Default) +) +``` From 43ac09a79b33f831c50aef44f1b0570292b341c8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 31 Mar 2020 11:28:48 +0600 Subject: [PATCH 18/20] fixes in startGettingUpdates --- CHANGELOG.md | 6 ++++++ .../extensions/api/GetUpdates.kt | 4 ++-- .../extensions/api/updates/UpdatesPolling.kt | 18 +++++++++++++++--- .../TelegramBotAPI/requests/GetUpdates.kt | 8 +++++++- .../TelegramBotAPI/types/Common.kt | 1 + 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80049c9e1f..41011eb580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ * `AddAnimatedStickerToSet` request was added * `SetStickerSetThumb` request was added * Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction` + * `getUpdatesLimit` was added to be ensure in get updates limit + * `GetUpdates` now will check count of requesting updates and throw exception if it is not in range `1 .. 100` + * `GetUpdates#limit` now is not nullable and by default set up to 100 * `TelegramBotAPI-extensions-api`: * Extensions `sendDice` was added * Extension `getMyCommands` request was added @@ -28,6 +31,9 @@ * **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`** * Extensions `addAnimatedStickerToSet` was added * Extensions `setStickerSetThumb` was added + * Extension `startGettingUpdates` now will drop `SentMediaGroupUpdate` in case if it is the last in updates group + and size of retrieved updates is equal to 100 (max count of retrieved updates) + * Extensions `getUpdates` now will receive only not nullable `limit` parameter ## 0.25.0 diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt index 728dfb0ec5..778ef5e983 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update suspend fun RequestsExecutor.getUpdates( offset: UpdateIdentifier? = null, - limit: Int? = null, + limit: Int = getUpdatesLimit.last, timeout: Seconds? = null, allowed_updates: List? = ALL_UPDATES_LIST ) = execute( @@ -18,7 +18,7 @@ suspend fun RequestsExecutor.getUpdates( suspend fun RequestsExecutor.getUpdates( lastUpdate: Update, - limit: Int? = null, + limit: Int = getUpdatesLimit.last, timeout: Seconds? = null, allowed_updates: List? = ALL_UPDATES_LIST ) = getUpdates( diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt index bd4e99f8ab..fe2fba5f2e 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt @@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestExceptio import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates -import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds -import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update @@ -30,7 +29,20 @@ fun RequestsExecutor.startGettingOfUpdates( offset = lastUpdateIdentifier?.plus(1), timeout = timeoutSeconds, allowed_updates = allowedUpdates - ).convertWithMediaGroupUpdates() + ).let { originalUpdates -> + val converted = originalUpdates.convertWithMediaGroupUpdates() + /** + * Dirty hack for cases when the media group was retrieved not fully: + * + * We are throw out the last media group and will reretrieve it again in the next get updates + * and it will guarantee that it is full + */ + if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) { + converted - converted.last() + } else { + converted + } + } supervisorScope { for (update in updates) { diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index 5f89bcc368..3169c63936 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -14,7 +14,7 @@ private val updatesListSerializer = ListSerializer( @Serializable data class GetUpdates( val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates - val limit: Int? = null, + val limit: Int = getUpdatesLimit.last, val timeout: Seconds? = null, val allowed_updates: List? = ALL_UPDATES_LIST ): SimpleRequest> { @@ -25,4 +25,10 @@ data class GetUpdates( override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (limit !in getUpdatesLimit) { + error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)") + } + } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 1b5ba30e63..97b58db5d1 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -23,6 +23,7 @@ typealias DiceResult = Int typealias Seconds = Int +val getUpdatesLimit = 1 .. 100 val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 until 1024 val textLength = 0 until 4096 From 7e6e892c4567b015eaa2a2a2b7b999fbdb796557 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 31 Mar 2020 11:31:24 +0600 Subject: [PATCH 19/20] libraries updates --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41011eb580..4eced9cdc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.26.0 +* `Common`: + * Versions updates: + * `Klock`: `1.10.0` -> `1.10.3` * `TelegramBotAPI`: * Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice)) * Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice)) diff --git a/gradle.properties b/gradle.properties index c84053e095..139532f266 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official kotlin_version=1.3.71 kotlin_coroutines_version=1.3.5 kotlin_serialisation_runtime_version=0.20.0 -klock_version=1.10.0 +klock_version=1.10.3 uuid_version=0.1.0 ktor_version=1.3.2 From 8293d6683c213e2e078b96618639a9b186409f0c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 31 Mar 2020 11:41:58 +0600 Subject: [PATCH 20/20] optimize imports --- .../TelegramBotAPI/extensions/api/bot/SetMyCommands.kt | 1 - .../TelegramBotAPI/requests/bot/SetMyCommands.kt | 1 - .../requests/stickers/AddAnimatedStickerToSet.kt | 2 +- .../TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt | 1 - .../requests/stickers/CreateNewAnimatedStickerSet.kt | 1 - .../requests/stickers/CreateNewStaticStickerSet.kt | 1 - .../requests/stickers/abstracts/StickerSetAction.kt | 1 - .../TelegramBotAPI/types/message/RawMessage.kt | 3 ++- 8 files changed, 3 insertions(+), 8 deletions(-) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt index d8da9a63bf..5347510a5f 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt @@ -1,7 +1,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt index 1b2e262511..44456d5787 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.bot import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* import kotlinx.serialization.* -import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.serializer @Serializable diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt index b73c71d320..105cf9e12b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt @@ -3,10 +3,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* + fun AddAnimatedStickerToSet( userId: UserId, stickerSetName: String, diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt index ac92cb1f5c..769cd69e55 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt index 800a3e1a6f..d512b88acf 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt index 70ab9bd519..2fda4511cc 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt @@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction -import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt index 4336052d98..7f051ebfc3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt @@ -2,7 +2,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.UserId -import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 99a0fa25bb..ae8efe3dbc 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -19,7 +19,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.Success 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 kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable import kotlin.reflect.KClass // TODO:: add PassportData type