From 274afe8efc016b909315ebc9329b9eea31f0b2cc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 30 Mar 2020 22:12:31 +0600 Subject: [PATCH] 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" +}