From 9cd2a6220c3b0b190e6c0871cf33646968891162 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:29:34 +0600 Subject: [PATCH] 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()