diff --git a/CHANGELOG.md b/CHANGELOG.md index 047f7877d1..3ae378e21b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ **THIS VERSION CONTAINS BREAKING CHANGES**: -* Fully reworked mechanism of stickers creating +* Fully reworked mechanism of stickers creating and adding ## 6.1.0 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddStaticStickerToSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddStaticStickerToSet.kt index 58491ea03c..5008e44952 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddStaticStickerToSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddStaticStickerToSet.kt @@ -2,89 +2,94 @@ package dev.inmo.tgbotapi.extensions.api.stickers import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.requests.abstracts.InputFile import dev.inmo.tgbotapi.requests.abstracts.MultipartFile -import dev.inmo.tgbotapi.requests.stickers.AddStaticStickerToSet +import dev.inmo.tgbotapi.requests.stickers.AddStickerToSet +import dev.inmo.tgbotapi.requests.stickers.InputSticker +import dev.inmo.tgbotapi.types.StickerType import dev.inmo.tgbotapi.types.chat.CommonUser import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.StickerSet -suspend fun TelegramBot.addStaticStickerToSet( +suspend fun TelegramBot.addStickerToSet( userId: UserId, stickerSetName: String, - sticker: FileId, - emojis: String, - maskPosition: MaskPosition? = null + inputSticker: InputSticker ) = execute( - AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + AddStickerToSet(userId, stickerSetName, inputSticker) ) -suspend fun TelegramBot.addStaticStickerToSet( - userId: UserId, - stickerSetName: String, - sticker: MultipartFile, - emojis: String, - maskPosition: MaskPosition? = null -) = execute( - AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) -) - -suspend fun TelegramBot.addStaticStickerToSet( - user: CommonUser, - stickerSetName: String, - sticker: FileId, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - user.id, stickerSetName, sticker, emojis, maskPosition -) - -suspend fun TelegramBot.addStaticStickerToSet( - user: CommonUser, - stickerSetName: String, - sticker: MultipartFile, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - user.id, stickerSetName, sticker, emojis, maskPosition -) - -suspend fun TelegramBot.addStaticStickerToSet( +suspend fun TelegramBot.addStickerToSet( userId: UserId, stickerSet: StickerSet, - sticker: FileId, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - userId, stickerSet.name, sticker, emojis, maskPosition + sticker: InputFile, + emojis: List, + keywords: List = emptyList() +) = addStickerToSet( + userId, + stickerSet.name, + when (stickerSet.stickerType) { + StickerType.CustomEmoji -> InputSticker.WithKeywords.CustomEmoji( + sticker, + emojis, + keywords + ) + StickerType.Mask -> error("Unable to create Mask sticker to the set without maskPosition parameter") + StickerType.Regular -> InputSticker.WithKeywords.Regular( + sticker, + emojis, + keywords + ) + is StickerType.Unknown -> error("Unable to create sticker to the set with type ${stickerSet.stickerType}") + } ) -suspend fun TelegramBot.addStaticStickerToSet( +suspend fun TelegramBot.addStickerToSet( userId: UserId, stickerSet: StickerSet, - sticker: MultipartFile, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - userId, stickerSet.name, sticker, emojis, maskPosition + sticker: InputFile, + emojis: List, + maskPosition: MaskPosition +) = addStickerToSet( + userId, + stickerSet.name, + when (stickerSet.stickerType) { + StickerType.CustomEmoji -> InputSticker.WithKeywords.CustomEmoji( + sticker, + emojis, + emptyList() + ) + StickerType.Mask -> InputSticker.Mask( + sticker, + emojis, + maskPosition + ) + StickerType.Regular -> InputSticker.WithKeywords.Regular( + sticker, + emojis, + emptyList() + ) + is StickerType.Unknown -> error("Unable to create sticker to the set with type ${stickerSet.stickerType}") + } ) -suspend fun TelegramBot.addStaticStickerToSet( +suspend fun TelegramBot.addStickerToSet( user: CommonUser, stickerSet: StickerSet, - sticker: FileId, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - user.id, stickerSet.name, sticker, emojis, maskPosition + sticker: InputFile, + emojis: List, + keywords: List = emptyList() +) = addStickerToSet( + user.id, stickerSet, sticker, emojis, keywords ) -suspend fun TelegramBot.addStaticStickerToSet( +suspend fun TelegramBot.addStickerToSet( user: CommonUser, stickerSet: StickerSet, - sticker: MultipartFile, - emojis: String, - maskPosition: MaskPosition? = null -) = addStaticStickerToSet( - user.id, stickerSet.name, sticker, emojis, maskPosition + sticker: InputFile, + emojis: List, + maskPosition: MaskPosition +) = addStickerToSet( + user.id, stickerSet, sticker, emojis, maskPosition ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddAnimatedStickerToSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddAnimatedStickerToSet.kt deleted file mode 100644 index 3789e835f2..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddAnimatedStickerToSet.kt +++ /dev/null @@ -1,50 +0,0 @@ -package dev.inmo.tgbotapi.requests.stickers - -import dev.inmo.tgbotapi.requests.abstracts.* -import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest -import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition -import kotlinx.serialization.* - -fun AddAnimatedStickerToSet( - userId: UserId, - stickerSetName: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition? = null -): Request { - val data = AddAnimatedStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) - return when (sticker) { - is MultipartFile -> CommonMultipartFileRequest( - data, - mapOf(tgsStickerField to sticker) - ) - is FileId -> data - } -} - -@Serializable -data class AddAnimatedStickerToSet internal constructor( - @SerialName(userIdField) - override val userId: UserId, - @SerialName(nameField) - override val name: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(tgsStickerField) - val sticker: FileId? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null -) : StandardStickerSetAction { - init { - if(emojis.isEmpty()) { - throw IllegalArgumentException("Emojis must not be empty") - } - } - - override val requestSerializer: SerializationStrategy<*> - get() = serializer() - - override fun method(): String = "addStickerToSet" -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStaticStickerToSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStaticStickerToSet.kt deleted file mode 100644 index 521e6ca245..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStaticStickerToSet.kt +++ /dev/null @@ -1,50 +0,0 @@ -package dev.inmo.tgbotapi.requests.stickers - -import dev.inmo.tgbotapi.requests.abstracts.* -import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest -import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.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 - } -} - -@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 -) : StandardStickerSetAction { - init { - if(emojis.isEmpty()) { - throw IllegalArgumentException("Emojis must not be empty") - } - } - - override val requestSerializer: SerializationStrategy<*> - get() = serializer() - - override fun method(): String = "addStickerToSet" -} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStickerToSet.kt similarity index 52% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStickerToSet.kt index 456e452dc1..a5a1ce7cf2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddStickerToSet.kt @@ -4,45 +4,32 @@ import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition import kotlinx.serialization.* -fun AddVideoStickerToSet( +fun AddStickerToSet( userId: UserId, stickerSetName: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition? = null + inputSticker: InputSticker ): Request { - val data = AddVideoStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) - return when (sticker) { + val data = AddStickerToSetData(userId, stickerSetName, inputSticker) + return when (val sticker = inputSticker.sticker) { is MultipartFile -> CommonMultipartFileRequest( data, - mapOf(webmStickerField to sticker) + mapOf(sticker.fileId to sticker) ) is FileId -> data } } @Serializable -data class AddVideoStickerToSet internal constructor( +data class AddStickerToSetData internal constructor( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) override val name: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(webmStickerField) - val sticker: FileId? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null + @SerialName(stickerField) + override val inputSticker: InputSticker ) : StandardStickerSetAction { - init { - if(emojis.isEmpty()) { - throw IllegalArgumentException("Emojis must not be empty") - } - } - override val requestSerializer: SerializationStrategy<*> get() = serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StandardStickerSetAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StandardStickerSetAction.kt index ea7368cba7..4df281c4c2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StandardStickerSetAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StandardStickerSetAction.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.requests.stickers.abstracts +import dev.inmo.tgbotapi.requests.stickers.InputSticker import dev.inmo.tgbotapi.types.stickers.MaskPosition interface StandardStickerSetAction : OwnerStickerSetAction { - val emojis: String // must be more than one - val maskPosition: MaskPosition? + val inputSticker: InputSticker }