diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d7d0d378..047f7877d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 7.0.0 +**THIS VERSION CONTAINS BREAKING CHANGES**: + +* Fully reworked mechanism of stickers creating + ## 6.1.0 * `Versions`: diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewAnimatedStickerSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewAnimatedStickerSet.kt deleted file mode 100644 index 57a024cfec..0000000000 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewAnimatedStickerSet.kt +++ /dev/null @@ -1,58 +0,0 @@ -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.MultipartFile -import dev.inmo.tgbotapi.requests.stickers.CreateNewAnimatedStickerSet -import dev.inmo.tgbotapi.types.chat.CommonUser -import dev.inmo.tgbotapi.types.UserId -import dev.inmo.tgbotapi.types.stickers.MaskPosition - -suspend fun TelegramBot.createNewAnimatedStickerSet( - userId: UserId, - name: String, - title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = execute( - CreateNewAnimatedStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) -) - -suspend fun TelegramBot.createNewAnimatedStickerSet( - userId: UserId, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = execute( - CreateNewAnimatedStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) -) - - -suspend fun TelegramBot.createNewAnimatedStickerSet( - user: CommonUser, - name: String, - title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewAnimatedStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition -) - -suspend fun TelegramBot.createNewAnimatedStickerSet( - user: CommonUser, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewAnimatedStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition -) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewStaticStickerSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewStaticStickerSet.kt index 19f512c8a2..cbd0b41fdb 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewStaticStickerSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewStaticStickerSet.kt @@ -3,56 +3,30 @@ 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.MultipartFile -import dev.inmo.tgbotapi.requests.stickers.CreateNewStaticStickerSet +import dev.inmo.tgbotapi.requests.stickers.CreateNewStickerSet +import dev.inmo.tgbotapi.requests.stickers.InputSticker +import dev.inmo.tgbotapi.types.StickerFormat import dev.inmo.tgbotapi.types.chat.CommonUser import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.stickers.MaskPosition -suspend fun TelegramBot.createNewStaticStickerSet( +suspend fun TelegramBot.createNewStickerSet( userId: UserId, name: String, title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null + stickersFormat: StickerFormat, + stickers: List, ) = execute( - CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) -) - -suspend fun TelegramBot.createNewStaticStickerSet( - userId: UserId, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = execute( - CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) + CreateNewStickerSet(userId, name, title, stickersFormat, stickers) ) -suspend fun TelegramBot.createNewStaticStickerSet( +suspend fun TelegramBot.createNewStickerSet( user: CommonUser, name: String, title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewStaticStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition -) - -suspend fun TelegramBot.createNewStaticStickerSet( - user: CommonUser, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewStaticStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition + stickersFormat: StickerFormat, + stickers: List, +) = createNewStickerSet( + user.id, name, title, stickersFormat, stickers ) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewVideoStickerSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewVideoStickerSet.kt deleted file mode 100644 index 9e8360244a..0000000000 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewVideoStickerSet.kt +++ /dev/null @@ -1,58 +0,0 @@ -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.MultipartFile -import dev.inmo.tgbotapi.requests.stickers.CreateNewVideoStickerSet -import dev.inmo.tgbotapi.types.chat.CommonUser -import dev.inmo.tgbotapi.types.UserId -import dev.inmo.tgbotapi.types.stickers.MaskPosition - -suspend fun TelegramBot.createNewVideoStickerSet( - userId: UserId, - name: String, - title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = execute( - CreateNewVideoStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) -) - -suspend fun TelegramBot.createNewVideoStickerSet( - userId: UserId, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = execute( - CreateNewVideoStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) -) - - -suspend fun TelegramBot.createNewVideoStickerSet( - user: CommonUser, - name: String, - title: String, - sticker: FileId, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewVideoStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition -) - -suspend fun TelegramBot.createNewVideoStickerSet( - user: CommonUser, - name: String, - title: String, - sticker: MultipartFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -) = createNewVideoStickerSet( - user.id, name, title, sticker, emojis, containsMasks, maskPosition -) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewAnimatedStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewAnimatedStickerSet.kt deleted file mode 100644 index 0dbebdb595..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewAnimatedStickerSet.kt +++ /dev/null @@ -1,40 +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.CreateStickerSetAction -import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition -import kotlinx.serialization.* - -@Serializable -@Deprecated("Use CreateNewStickerSet class instead") -data class CreateNewAnimatedStickerSet internal constructor( - @SerialName(userIdField) - override val userId: UserId, - @SerialName(nameField) - override val name: String, - @SerialName(titleField) - override val title: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(tgsStickerField) - val sticker: FileId? = null, - @SerialName(containsMasksField) - @Deprecated("Will be removed soon due to its redundancy") - val containsMasks: Boolean? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null -) : CreateStickerSetAction { - 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/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStaticStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStaticStickerSet.kt deleted file mode 100644 index 6e12b9d012..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStaticStickerSet.kt +++ /dev/null @@ -1,40 +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.CreateStickerSetAction -import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition -import kotlinx.serialization.* - -@Serializable -@Deprecated("Use CreateNewStickerSet class instead") -data class CreateNewStaticStickerSet internal constructor( - @SerialName(userIdField) - override val userId: UserId, - @SerialName(nameField) - override val name: String, - @SerialName(titleField) - override val title: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(pngStickerField) - val sticker: FileId? = null, - @SerialName(containsMasksField) - @Deprecated("Will be removed soon due to its redundancy") - val containsMasks: Boolean? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null -) : CreateStickerSetAction { - 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/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStickerSet.kt index 537c5f70b5..7895e7ef93 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStickerSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewStickerSet.kt @@ -7,36 +7,30 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.stickers.MaskPosition import kotlinx.serialization.* -internal fun CreateNewStickerSet( +/** + * Will create one of [CreateNewStickerSet] types based on the first element of [stickers] + * + * @param needsRepainting Will be used only if you are creating custom emojis sticker pack (by passing [stickers] with + * type [InputSticker.WithKeywords.CustomEmoji]) + */ +fun CreateNewStickerSet( userId: UserId, name: String, title: String, - emojis: String, - stickerType: StickerType = StickerType.Regular, - pngSticker: InputFile? = null, - tgsSticker: InputFile? = null, - webmSticker: InputFile? = null, - maskPosition: MaskPosition? = null + stickersFormat: StickerFormat, + stickers: List, + needsRepainting: Boolean? = null ): Request { - val data = CreateNewStickerSet( - userId, - name, - title, - emojis, - stickerType, - pngSticker as? FileId, - tgsSticker as? FileId, - webmSticker as? FileId, - maskPosition - ) - return if (pngSticker is MultipartFile || tgsSticker is MultipartFile || webmSticker is MultipartFile) { + val data = when(stickers.first()) { + is InputSticker.Mask -> CreateNewStickerSet.Mask(userId, name, title, stickersFormat, stickers.filterIsInstance()) + is InputSticker.WithKeywords.CustomEmoji -> CreateNewStickerSet.CustomEmoji(userId, name, title, stickersFormat, stickers.filterIsInstance(), needsRepainting) + is InputSticker.WithKeywords.Regular -> CreateNewStickerSet.Regular(userId, name, title, stickersFormat, stickers.filterIsInstance()) + } + val multipartParts = stickers.mapNotNull { (it.sticker as? MultipartFile) } + return if (multipartParts.isNotEmpty()) { CommonMultipartFileRequest( data, - listOfNotNull( - (pngSticker as? MultipartFile) ?.let { pngStickerField to it }, - (tgsSticker as? MultipartFile) ?.let { tgsStickerField to it }, - (webmSticker as? MultipartFile) ?.let { webmStickerField to it }, - ).toMap() + multipartParts.associateBy { it.fileId } ) } else { data @@ -44,34 +38,67 @@ internal fun CreateNewStickerSet( } @Serializable -data class CreateNewStickerSet internal constructor( - @SerialName(userIdField) - override val userId: UserId, - @SerialName(nameField) - override val name: String, - @SerialName(titleField) - override val title: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(stickerTypeField) - val stickerType: StickerType = StickerType.Regular, - @SerialName(pngStickerField) - val pngSticker: FileId? = null, - @SerialName(tgsStickerField) - val tgsSticker: FileId? = null, - @SerialName(webmStickerField) - val webmSticker: FileId? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null -) : CreateStickerSetAction { - init { - if(emojis.isEmpty()) { - throw IllegalArgumentException("Emojis must not be empty") - } - } +sealed interface CreateNewStickerSet : CreateStickerSetAction { + val stickerType: StickerType + val stickers: List + val stickersFormat: StickerFormat override val requestSerializer: SerializationStrategy<*> get() = serializer() override fun method(): String = "createNewStickerSet" + + @Serializable + data class Regular( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(titleField) + override val title: String, + @SerialName(stickerFormatField) + override val stickersFormat: StickerFormat, + @SerialName(stickersField) + override val stickers: List + ) : CreateNewStickerSet { + @SerialName(stickerTypeField) + override val stickerType: StickerType + get() = StickerType.Regular + } + @Serializable + data class Mask( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(titleField) + override val title: String, + @SerialName(stickerFormatField) + override val stickersFormat: StickerFormat, + @SerialName(stickersField) + override val stickers: List + ) : CreateNewStickerSet { + @SerialName(stickerTypeField) + override val stickerType: StickerType + get() = StickerType.Mask + } + @Serializable + data class CustomEmoji( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(titleField) + override val title: String, + @SerialName(stickerFormatField) + override val stickersFormat: StickerFormat, + @SerialName(stickersField) + override val stickers: List, + @SerialName(needsRepaintingField) + val needsRepainting: Boolean? = null + ) : CreateNewStickerSet { + @SerialName(stickerTypeField) + override val stickerType: StickerType + get() = StickerType.CustomEmoji + } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt deleted file mode 100644 index cfaeb78075..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt +++ /dev/null @@ -1,40 +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.CreateStickerSetAction -import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition -import kotlinx.serialization.* - -@Serializable -@Deprecated("Use CreateNewStickerSet class instead") -data class CreateNewVideoStickerSet internal constructor( - @SerialName(userIdField) - override val userId: UserId, - @SerialName(nameField) - override val name: String, - @SerialName(titleField) - override val title: String, - @SerialName(emojisField) - override val emojis: String, - @SerialName(webmStickerField) - val sticker: FileId? = null, - @SerialName(containsMasksField) - @Deprecated("Will be removed soon due to its redundancy") - val containsMasks: Boolean? = null, - @SerialName(maskPositionField) - override val maskPosition: MaskPosition? = null -) : CreateStickerSetAction { - 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/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/InputSticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/InputSticker.kt new file mode 100644 index 0000000000..aaac6fc0cc --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/InputSticker.kt @@ -0,0 +1,53 @@ +package dev.inmo.tgbotapi.requests.stickers + +import dev.inmo.tgbotapi.requests.abstracts.InputFile +import dev.inmo.tgbotapi.types.emojiListField +import dev.inmo.tgbotapi.types.keywordsField +import dev.inmo.tgbotapi.types.maskPositionField +import dev.inmo.tgbotapi.types.stickerField +import dev.inmo.tgbotapi.types.stickers.MaskPosition +import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@ClassCastsIncluded +@Serializable +sealed interface InputSticker { + val sticker: InputFile + val emojisList: List + + @Serializable + data class Mask( + @SerialName(stickerField) + override val sticker: InputFile, + @SerialName(emojiListField) + override val emojisList: List, + @SerialName(maskPositionField) + val maskPosition: MaskPosition + ) : InputSticker + + @Serializable + sealed interface WithKeywords : InputSticker { + val keywords: List + + @Serializable + data class Regular( + @SerialName(stickerField) + override val sticker: InputFile, + @SerialName(emojiListField) + override val emojisList: List, + @SerialName(keywordsField) + override val keywords: List + ) : WithKeywords + + @Serializable + data class CustomEmoji( + @SerialName(stickerField) + override val sticker: InputFile, + @SerialName(emojiListField) + override val emojisList: List, + @SerialName(keywordsField) + override val keywords: List + ) : WithKeywords + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/NewCreateNewStickerSetFunctions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/NewCreateNewStickerSetFunctions.kt deleted file mode 100644 index 2cd56868bf..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/NewCreateNewStickerSetFunctions.kt +++ /dev/null @@ -1,105 +0,0 @@ -package dev.inmo.tgbotapi.requests.stickers - -import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.StickerType -import dev.inmo.tgbotapi.types.UserId -import dev.inmo.tgbotapi.types.stickers.MaskPosition - - -fun CreateNewRegularStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Regular, - pngSticker = sticker -) - -fun CreateNewRegularVideoStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Regular, - webmSticker = sticker -) - -fun CreateNewRegularAnimatedStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Regular, - tgsSticker = sticker -) - - -fun CreateNewMaskStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Mask, - pngSticker = sticker, - maskPosition = maskPosition -) - -fun CreateNewMaskVideoStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Mask, - webmSticker = sticker, - maskPosition = maskPosition -) - -fun CreateNewMaskAnimatedStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - maskPosition: MaskPosition -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - StickerType.Mask, - tgsSticker = sticker, - maskPosition = maskPosition -) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/OldCreateNewStickerSetFunctions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/OldCreateNewStickerSetFunctions.kt deleted file mode 100644 index 69f747c53f..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/OldCreateNewStickerSetFunctions.kt +++ /dev/null @@ -1,80 +0,0 @@ -package dev.inmo.tgbotapi.requests.stickers - -import dev.inmo.tgbotapi.requests.abstracts.InputFile -import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.StickerType -import dev.inmo.tgbotapi.types.UserId -import dev.inmo.tgbotapi.types.stickers.MaskPosition - - -fun CreateNewVideoStickerSet( - userId: UserId, - linkName: String, - title: String, - sticker: InputFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -): Request = CreateNewStickerSet( - userId, - linkName, - title, - emojis, - if (containsMasks == true) StickerType.Mask else StickerType.Regular, - webmSticker = sticker, - maskPosition = maskPosition -) - -fun CreateNewStaticStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - if (containsMasks == true) StickerType.Mask else StickerType.Regular, - pngSticker = sticker, - maskPosition = maskPosition -) - -fun CreateNewStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - if (containsMasks == true) StickerType.Mask else StickerType.Regular, - pngSticker = sticker, - maskPosition = maskPosition -) - -fun CreateNewAnimatedStickerSet( - userId: UserId, - name: String, - title: String, - sticker: InputFile, - emojis: String, - containsMasks: Boolean? = null, - maskPosition: MaskPosition? = null -): Request = CreateNewStickerSet( - userId, - name, - title, - emojis, - if (containsMasks == true) StickerType.Mask else StickerType.Regular, - tgsSticker = sticker, - maskPosition = maskPosition -) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt index 31091c0592..7ef6ee655f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt @@ -1,5 +1,5 @@ package dev.inmo.tgbotapi.requests.stickers.abstracts -interface CreateStickerSetAction : StandardStickerSetAction { +interface CreateStickerSetAction : OwnerStickerSetAction { val title: String } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index cb3abb8999..73fa5dec7b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -83,6 +83,38 @@ sealed interface StickerType { } } +@Serializable(StickerFormat.Serializer::class) +sealed interface StickerFormat { + val type: String + + @Serializable + object Static : StickerFormat { override val type: String = "static" } + @Serializable + object Animated : StickerFormat { override val type: String = "animated" } + @Serializable + object Video : StickerFormat { override val type: String = "video" } + @Serializable + data class Unknown(override val type: String = "custom_emoji") : StickerFormat + + object Serializer : KSerializer { + override val descriptor: SerialDescriptor = String.serializer().descriptor + + override fun deserialize(decoder: Decoder): StickerFormat { + return when (val type = decoder.decodeString()) { + Static.type -> Static + Animated.type -> Animated + Video.type -> Video + else -> Unknown(type) + } + } + + override fun serialize(encoder: Encoder, value: StickerFormat) { + encoder.encodeString(value.type) + } + + } +} + val usernameRegex = Regex("@[\\w\\d_]+") val degreesLimit = 1 .. 360 @@ -388,6 +420,8 @@ const val webmStickerField = "webm_sticker" const val oldChatMemberField = "old_chat_member" const val newChatMemberField = "new_chat_member" const val stickerTypeField = "sticker_type" +const val stickerFormatField = "sticker_format" +const val needsRepaintingField = "needs_repainting" const val okField = "ok" const val captionField = "caption" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt index e017de9a20..48932491ab 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/Sticker.kt @@ -330,6 +330,7 @@ data class MaskVideoSticker( @Serializable sealed interface CustomEmojiSticker : Sticker { val customEmojiId: CustomEmojiId + val needsRepainting: Boolean } @Serializable @@ -352,6 +353,8 @@ data class CustomEmojiSimpleSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(needsRepaintingField) + override val needsRepainting: Boolean = false ) : CustomEmojiSticker @Serializable data class CustomEmojiAnimatedSticker( @@ -373,6 +376,8 @@ data class CustomEmojiAnimatedSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(needsRepaintingField) + override val needsRepainting: Boolean = false, ) : CustomEmojiSticker, AnimatedSticker @Serializable data class CustomEmojiVideoSticker( @@ -394,6 +399,8 @@ data class CustomEmojiVideoSticker( override val stickerSetName: StickerSetName? = null, @SerialName(fileSizeField) override val fileSize: Long? = null, + @SerialName(needsRepaintingField) + override val needsRepainting: Boolean = false, ) : CustomEmojiSticker, VideoSticker @Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stickers/StickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stickers/StickerSet.kt index fc53396886..e86e5215a2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stickers/StickerSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/stickers/StickerSet.kt @@ -30,7 +30,10 @@ sealed interface StickerSet { get() = false val isVideo: Boolean get() = false + val thumbnail: PhotoSize? + @Deprecated("Renamed in telegram bot api") val thumb: PhotoSize? + get() = thumbnail @Deprecated("Will be removed soon due to its redundancy") val containsMasks: Boolean get() = this is MaskStickerSet @@ -146,7 +149,7 @@ data class RegularSimpleStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : RegularStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -162,7 +165,7 @@ data class RegularAnimatedStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : RegularStickerSet, AnimatedStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -178,7 +181,7 @@ data class RegularVideoStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : RegularStickerSet, VideoStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -194,7 +197,7 @@ data class MaskSimpleStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : MaskStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -210,7 +213,7 @@ data class MaskAnimatedStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : MaskStickerSet, AnimatedStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -226,7 +229,7 @@ data class MaskVideoStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : MaskStickerSet, VideoStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -242,7 +245,7 @@ data class CustomEmojiSimpleStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : CustomEmojiStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -258,7 +261,7 @@ data class CustomEmojiAnimatedStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : CustomEmojiStickerSet, AnimatedStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -274,7 +277,7 @@ data class CustomEmojiVideoStickerSet( @SerialName(stickersField) override val stickers: List, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null + override val thumbnail: PhotoSize? = null ) : CustomEmojiStickerSet, VideoStickerSet { @SerialName(stickerTypeField) @EncodeDefault @@ -292,6 +295,6 @@ data class UnknownStickerSet( @SerialName(stickerTypeField) override val stickerType: StickerType, @SerialName(thumbnailField) - override val thumb: PhotoSize? = null, + override val thumbnail: PhotoSize? = null, val raw: JsonElement ) : CustomEmojiStickerSet, VideoStickerSet