From 3547c093831a5e74d04a74823422f07c6e77217f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 31 Jan 2022 17:48:10 +0600 Subject: [PATCH 1/7] start 0.38.4 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89834efb6b..3f67eb0a46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.38.4 + ## 0.38.3 * `Common`: diff --git a/gradle.properties b/gradle.properties index ae5123c8ad..c005fc261b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,6 @@ javax_activation_version=1.1.1 dokka_version=1.6.10 library_group=dev.inmo -library_version=0.38.3 +library_version=0.38.4 github_release_plugin_version=2.2.12 From eee9fe439f4e5ec7861a445c9c9581d79722020b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 31 Jan 2022 17:51:34 +0600 Subject: [PATCH 2/7] fix of #529 --- CHANGELOG.md | 3 +++ .../types/files/{PathedFile.kt => PathedFileAsStream.kt} | 0 2 files changed, 3 insertions(+) rename tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/{PathedFile.kt => PathedFileAsStream.kt} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f67eb0a46..474bc7e63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.4 +* `Utils`: + * Rename `PathedFile` to avoid clash with core file (fix of [#529](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/529)) + ## 0.38.3 * `Common`: diff --git a/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt b/tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFileAsStream.kt similarity index 100% rename from tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFile.kt rename to tgbotapi.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/files/PathedFileAsStream.kt From 0c2fe6bce7654c2fae22c60734a4936549f53ebc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Feb 2022 16:23:26 +0600 Subject: [PATCH 3/7] support of Telegram Bot API 5.7 --- CHANGELOG.md | 6 + README.md | 2 +- gradle.properties | 2 +- .../extensions/api/get/GetStickerSet.kt | 2 +- .../tgbotapi/extensions/api/send/Replies.kt | 1 + .../extensions/api/send/media/SendSticker.kt | 2 +- .../api/stickers/AddVideoStickerToSet.kt | 90 ++++++++++ .../api/stickers/CreateNewVideoStickerSet.kt | 54 ++++++ .../api/stickers/DeleteStickerFromSet.kt | 2 +- .../api/stickers/SetStickerPositionInSet.kt | 2 +- .../requests/stickers/AddVideoStickerToSet.kt | 50 ++++++ .../stickers/CreateNewVideoStickerSet.kt | 53 ++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 + .../dev/inmo/tgbotapi/types/files/Sticker.kt | 32 +--- .../tgbotapi/types/files/sticker/Sticker.kt | 158 ++++++++++++++++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 1 + .../message/content/media/StickerContent.kt | 2 +- .../tgbotapi/types/stickers/StickerSet.kt | 4 +- .../tgbotapi/extensions/utils/ClassCasts.kt | 1 + .../utils/extensions/raw/Message.kt | 1 + 20 files changed, 430 insertions(+), 37 deletions(-) create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddVideoStickerToSet.kt create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewVideoStickerSet.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/sticker/Sticker.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 474bc7e63d..d9cb237d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.38.4 +__This update contains including of [Telegram Bot API 5.7](https://core.telegram.org/bots/api-changelog#january-31-2022)__ + +* `Core`: + * Support of new fields `Sticker` + * Support of new fields `StickerSet` + * Support of new fields in creating of sticker set and sticker * `Utils`: * Rename `PathedFile` to avoid clash with core file (fix of [#529](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/529)) diff --git a/README.md b/README.md index 699b6edfff..2ca059ceff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.6-blue)](https://core.telegram.org/bots/api-changelog#december-30-2021) +# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.7-blue)](https://core.telegram.org/bots/api-changelog#january-31-2022) | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue)](https://forms.gle/2Hex2ynbHWHhi1KY7) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue)](https://t.me/InMoTelegramBotAPI) | |:---:| diff --git a/gradle.properties b/gradle.properties index c005fc261b..2b8cdf14cb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.4.12 uuid_version=0.4.0 ktor_version=1.6.7 -micro_utils_version=0.9.2 +micro_utils_version=0.9.4 javax_activation_version=1.1.1 diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt index 94400fa7a9..513f406e72 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetStickerSet.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.get import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.get.GetStickerSet -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker suspend fun TelegramBot.getStickerSet( name: String diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt index 7c7ec4bd22..f3134891dc 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/Replies.kt @@ -16,6 +16,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.dice.DiceAnimationType import dev.inmo.tgbotapi.types.files.* +import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.message.abstracts.Message diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt index d236e11cf3..4381032e80 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendSticker.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker /** * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddVideoStickerToSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddVideoStickerToSet.kt new file mode 100644 index 0000000000..c1efc2b577 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/AddVideoStickerToSet.kt @@ -0,0 +1,90 @@ +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.AddVideoStickerToSet +import dev.inmo.tgbotapi.types.CommonUser +import dev.inmo.tgbotapi.types.UserId +import dev.inmo.tgbotapi.types.stickers.MaskPosition +import dev.inmo.tgbotapi.types.stickers.StickerSet + +suspend fun TelegramBot.addVideoStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddVideoStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun TelegramBot.addVideoStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddVideoStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun TelegramBot.addVideoStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun TelegramBot.addVideoStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun TelegramBot.addVideoStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun TelegramBot.addVideoStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun TelegramBot.addVideoStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun TelegramBot.addVideoStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addVideoStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) 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 new file mode 100644 index 0000000000..805285a1ea --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/CreateNewVideoStickerSet.kt @@ -0,0 +1,54 @@ +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.CommonUser +import dev.inmo.tgbotapi.types.UserId +import dev.inmo.tgbotapi.types.stickers.MaskPosition + +suspend fun TelegramBot.createNewVideoStickerSet( + userId: UserId, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewVideoStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + +suspend fun TelegramBot.createNewVideoStickerSet( + userId: UserId, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewVideoStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + + +suspend fun TelegramBot.createNewVideoStickerSet( + user: CommonUser, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewVideoStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) + +suspend fun TelegramBot.createNewVideoStickerSet( + user: CommonUser, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewVideoStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/DeleteStickerFromSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/DeleteStickerFromSet.kt index 29be658518..a51fa3fdc4 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/DeleteStickerFromSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/DeleteStickerFromSet.kt @@ -3,7 +3,7 @@ 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.stickers.DeleteStickerFromSet -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker suspend fun TelegramBot.deleteStickerFromSet( sticker: FileId diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerPositionInSet.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerPositionInSet.kt index affe3f2056..3fa4da399c 100644 --- a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerPositionInSet.kt +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerPositionInSet.kt @@ -3,7 +3,7 @@ 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.stickers.SetStickerPositionInSet -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker suspend fun TelegramBot.setStickerPositionInSet( sticker: FileId, 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/AddVideoStickerToSet.kt new file mode 100644 index 0000000000..2706dd61a6 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt @@ -0,0 +1,50 @@ +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 AddVideoStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: InputFile, + emojis: String, + maskPosition: MaskPosition? = null +): Request { + val data = AddVideoStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +@Serializable +data class AddVideoStickerToSet 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 +) : 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/CreateNewVideoStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt new file mode 100644 index 0000000000..d05c6ad3b1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt @@ -0,0 +1,53 @@ +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 CreateNewVideoStickerSet( + userId: UserId, + name: String, + sticker: InputFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +): Request { + val data = CreateNewVideoStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +@Serializable +data class CreateNewVideoStickerSet 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(containsMasksField) + val containsMasks: Boolean? = 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 = "createNewStickerSet" +} 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 9260316960..0f432f60a8 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 @@ -168,6 +168,7 @@ const val botUsernameField = "bot_username" const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat" const val switchInlineQueryField = "switch_inline_query" const val isAnimatedField = "is_animated" +const val isVideoField = "is_video" const val inviteLinkField = "invite_link" const val pinnedMessageField = "pinned_message" const val customTitleField = "custom_title" @@ -265,6 +266,7 @@ const val canManageVoiceChatsField = "can_manage_voice_chats" const val canManageChatField = "can_manage_chat" const val pngStickerField = "png_sticker" const val tgsStickerField = "tgs_sticker" +const val webmStickerField = "webm_sticker" const val oldChatMemberField = "old_chat_member" const val newChatMemberField = "new_chat_member" 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 358b6a8b68..1027fba5c0 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 @@ -1,32 +1,6 @@ package dev.inmo.tgbotapi.types.files -import dev.inmo.tgbotapi.requests.abstracts.FileId -import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.files.abstracts.* -import dev.inmo.tgbotapi.types.stickers.MaskPosition -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable +import dev.inmo.tgbotapi.types.files.sticker.Sticker -@Serializable -data class Sticker( - @SerialName(fileIdField) - override val fileId: FileId, - @SerialName(fileUniqueIdField) - override val fileUniqueId: FileUniqueId, - @SerialName(widthField) - override val width: Int, - @SerialName(heightField) - override val height: Int, - @SerialName(thumbField) - override val thumb: PhotoSize? = null, - @SerialName(emojiField) - val emoji: String? = null, - @SerialName(stickerSetNameField) - val stickerSetName: StickerSetName? = null, - @SerialName(isAnimatedField) - val isAnimated: Boolean = false, - @SerialName(maskPositionField) - val maskPosition: MaskPosition? = null, - @SerialName(fileSizeField) - override val fileSize: Long? = null -) : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile +@Deprecated("Replaced", ReplaceWith("Sticker", "dev.inmo.tgbotapi.types.files.sticker.Sticker")) +typealias Sticker = Sticker diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/sticker/Sticker.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/sticker/Sticker.kt new file mode 100644 index 0000000000..76482afecf --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/sticker/Sticker.kt @@ -0,0 +1,158 @@ +package dev.inmo.tgbotapi.types.files.sticker + +import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.files.PhotoSize +import dev.inmo.tgbotapi.types.files.abstracts.* +import dev.inmo.tgbotapi.types.stickers.MaskPosition +import dev.inmo.tgbotapi.utils.RiskFeature +import kotlinx.serialization.* +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder + +@Serializable +@RiskFeature("This class is used for serialization/deserialization of Sticker interface") +data class StickerSurrogate( + val file_id: FileId, + val file_unique_id: FileUniqueId, + val width: Int, + val height: Int, + val is_animated: Boolean? = null, + val is_video: Boolean? = null, + val thumb: PhotoSize? = null, + val emoji: String? = null, + val set_name: StickerSetName? = null, + val mask_position: MaskPosition? = null, + val file_size: Long? = null +) + +// TODO:: Serializer +@Serializable(StickerSerializer::class) +sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile { + val emoji: String? + val maskPosition: MaskPosition? + val stickerSetName: StickerSetName? + + val isAnimated + get() = this is AnimatedSticker + val isVideo + get() = this is VideoSticker + + companion object { + fun serializer(): KSerializer = StickerSerializer + } +} + +object StickerSerializer : KSerializer { + override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor + + override fun deserialize(decoder: Decoder): Sticker { + val surrogate = StickerSurrogate.serializer().deserialize(decoder) + + return when { + surrogate.is_animated == true -> AnimatedSticker( + surrogate.file_id, + surrogate.file_unique_id, + surrogate.width, + surrogate.height, + surrogate.thumb, + surrogate.emoji, + surrogate.set_name, + surrogate.mask_position, + surrogate.file_size + ) + surrogate.is_video == true -> VideoSticker( + surrogate.file_id, + surrogate.file_unique_id, + surrogate.width, + surrogate.height, + surrogate.thumb, + surrogate.emoji, + surrogate.set_name, + surrogate.mask_position, + surrogate.file_size + ) + else -> SimpleSticker( + surrogate.file_id, + surrogate.file_unique_id, + surrogate.width, + surrogate.height, + surrogate.thumb, + surrogate.emoji, + surrogate.set_name, + surrogate.mask_position, + surrogate.file_size + ) + } + } + + override fun serialize(encoder: Encoder, value: Sticker) { + TODO("Not yet implemented") + } + +} + +@Serializable +data class SimpleSticker( + @SerialName(fileIdField) + override val fileId: FileId, + @SerialName(fileUniqueIdField) + override val fileUniqueId: FileUniqueId, + @SerialName(widthField) + override val width: Int, + @SerialName(heightField) + override val height: Int, + @SerialName(thumbField) + override val thumb: PhotoSize? = null, + @SerialName(emojiField) + override val emoji: String? = null, + @SerialName(stickerSetNameField) + override val stickerSetName: StickerSetName? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null, + @SerialName(fileSizeField) + override val fileSize: Long? = null, +) : Sticker +@Serializable +data class AnimatedSticker( + @SerialName(fileIdField) + override val fileId: FileId, + @SerialName(fileUniqueIdField) + override val fileUniqueId: FileUniqueId, + @SerialName(widthField) + override val width: Int, + @SerialName(heightField) + override val height: Int, + @SerialName(thumbField) + override val thumb: PhotoSize? = null, + @SerialName(emojiField) + override val emoji: String? = null, + @SerialName(stickerSetNameField) + override val stickerSetName: StickerSetName? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null, + @SerialName(fileSizeField) + override val fileSize: Long? = null, +) : Sticker +@Serializable +data class VideoSticker( + @SerialName(fileIdField) + override val fileId: FileId, + @SerialName(fileUniqueIdField) + override val fileUniqueId: FileUniqueId, + @SerialName(widthField) + override val width: Int, + @SerialName(heightField) + override val height: Int, + @SerialName(thumbField) + override val thumb: PhotoSize? = null, + @SerialName(emojiField) + override val emoji: String? = null, + @SerialName(stickerSetNameField) + override val stickerSetName: StickerSetName? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null, + @SerialName(fileSizeField) + override val fileSize: Long? = null, +) : Sticker diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 38868d2ae3..4022e0ddae 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* +import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.games.RawGame import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt index 16a81b62ad..3dc2d9978d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/media/StickerContent.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent import kotlinx.serialization.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 a7dc53ed3c..88d3f551d0 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 @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.stickers import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.PhotoSize -import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.sticker.Sticker import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,6 +16,8 @@ data class StickerSet( val stickers: List, @SerialName(isAnimatedField) val isAnimated: Boolean = false, + @SerialName(isVideoField) + val isVideo: Boolean = false, @SerialName(containsMasksField) val containsMasks: Boolean = false, @SerialName(thumbField) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index ca4d66cd9b..d21790ed95 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -31,6 +31,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.extended.* import dev.inmo.tgbotapi.types.dice.* import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.abstracts.* +import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.* import dev.inmo.tgbotapi.types.message.ChatEvents.* diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt index 8b20c66359..70cce93332 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Message.kt @@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.files.* +import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.* From fba6707f44e1bf0b0ce3e996c7d413f09362474f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Feb 2022 17:59:23 +0600 Subject: [PATCH 4/7] fixes in create sticker set methods --- .../api/stickers/CreateNewAnimatedStickerSet.kt | 12 ++++++++---- .../api/stickers/CreateNewStaticStickerSet.kt | 12 ++++++++---- .../api/stickers/CreateNewVideoStickerSet.kt | 12 ++++++++---- .../requests/stickers/CreateNewAnimatedStickerSet.kt | 8 ++++++-- .../requests/stickers/CreateNewStaticStickerSet.kt | 11 ++++++++--- .../requests/stickers/CreateNewVideoStickerSet.kt | 10 +++++++--- .../stickers/abstracts/CreateStickerSetAction.kt | 5 +++++ 7 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt 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 index c5bf76b6f3..4678ad058f 100644 --- 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 @@ -11,44 +11,48 @@ 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, sticker, emojis, containsMasks, maskPosition) + 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, sticker, emojis, containsMasks, maskPosition) + 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, sticker, emojis, containsMasks, maskPosition + 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, sticker, emojis, containsMasks, maskPosition + 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 be70b86597..0622223b81 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 @@ -11,44 +11,48 @@ import dev.inmo.tgbotapi.types.stickers.MaskPosition suspend fun TelegramBot.createNewStaticStickerSet( userId: UserId, name: String, + title: String, sticker: FileId, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = execute( - CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + 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, sticker, emojis, containsMasks, maskPosition) + CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) ) suspend fun TelegramBot.createNewStaticStickerSet( user: CommonUser, name: String, + title: String, sticker: FileId, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = createNewStaticStickerSet( - user.id, name, sticker, emojis, containsMasks, maskPosition + 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, sticker, emojis, containsMasks, maskPosition + user.id, name, title, sticker, emojis, containsMasks, maskPosition ) 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 index 805285a1ea..0f8f8dd0a5 100644 --- 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 @@ -11,44 +11,48 @@ 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, sticker, emojis, containsMasks, maskPosition) + 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, sticker, emojis, containsMasks, maskPosition) + 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, sticker, emojis, containsMasks, maskPosition + 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, sticker, emojis, containsMasks, maskPosition + 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 index 08aa78a3ec..c2d58f715a 100644 --- 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 @@ -2,6 +2,7 @@ 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 @@ -10,12 +11,13 @@ import kotlinx.serialization.* fun CreateNewAnimatedStickerSet( userId: UserId, name: String, + title: String, sticker: InputFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ): Request { - val data = CreateNewAnimatedStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + val data = CreateNewAnimatedStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -31,6 +33,8 @@ data class CreateNewAnimatedStickerSet internal constructor( override val userId: UserId, @SerialName(nameField) override val name: String, + @SerialName(titleField) + override val title: String, @SerialName(emojisField) override val emojis: String, @SerialName(tgsStickerField) @@ -39,7 +43,7 @@ data class CreateNewAnimatedStickerSet internal constructor( val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StandardStickerSetAction { +) : CreateStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") 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 index 97c92583ea..85b0d5a514 100644 --- 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 @@ -2,6 +2,7 @@ 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 @@ -10,12 +11,13 @@ import kotlinx.serialization.* fun CreateNewStaticStickerSet( userId: UserId, name: String, + title: String, sticker: InputFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ): Request { - val data = CreateNewStaticStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + val data = CreateNewStaticStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -28,11 +30,12 @@ fun CreateNewStaticStickerSet( fun CreateNewStickerSet( userId: UserId, name: String, + title: String, sticker: InputFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null -): Request = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +): Request = CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition) @Serializable data class CreateNewStaticStickerSet internal constructor( @@ -40,6 +43,8 @@ data class CreateNewStaticStickerSet internal constructor( override val userId: UserId, @SerialName(nameField) override val name: String, + @SerialName(titleField) + override val title: String, @SerialName(emojisField) override val emojis: String, @SerialName(pngStickerField) @@ -48,7 +53,7 @@ data class CreateNewStaticStickerSet internal constructor( val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StandardStickerSetAction { +) : CreateStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") 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 index d05c6ad3b1..0ba64a025c 100644 --- 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 @@ -2,6 +2,7 @@ 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 @@ -9,13 +10,14 @@ import kotlinx.serialization.* fun CreateNewVideoStickerSet( userId: UserId, - name: String, + linkName: String, + title: String, sticker: InputFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ): Request { - val data = CreateNewVideoStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + val data = CreateNewVideoStickerSet(userId, linkName, title, emojis, sticker as? FileId, containsMasks, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -31,6 +33,8 @@ data class CreateNewVideoStickerSet internal constructor( override val userId: UserId, @SerialName(nameField) override val name: String, + @SerialName(titleField) + override val title: String, @SerialName(emojisField) override val emojis: String, @SerialName(webmStickerField) @@ -39,7 +43,7 @@ data class CreateNewVideoStickerSet internal constructor( val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StandardStickerSetAction { +) : CreateStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") 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 new file mode 100644 index 0000000000..31091c0592 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/CreateStickerSetAction.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.requests.stickers.abstracts + +interface CreateStickerSetAction : StandardStickerSetAction { + val title: String +} From 6426ed657192844d312fd71a6313755a05cbb04e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Feb 2022 23:05:47 +0600 Subject: [PATCH 5/7] fixes --- .../inmo/tgbotapi/requests/stickers/AddAnimatedStickerToSet.kt | 2 +- .../dev/inmo/tgbotapi/requests/stickers/AddVideoStickerToSet.kt | 2 +- .../tgbotapi/requests/stickers/CreateNewAnimatedStickerSet.kt | 2 +- .../inmo/tgbotapi/requests/stickers/CreateNewVideoStickerSet.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) 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 index d2f3399407..3789e835f2 100644 --- 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 @@ -18,7 +18,7 @@ fun AddAnimatedStickerToSet( return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, - mapOf(pngStickerField to sticker) + mapOf(tgsStickerField to sticker) ) is FileId -> data } 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/AddVideoStickerToSet.kt index 2706dd61a6..456e452dc1 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/AddVideoStickerToSet.kt @@ -18,7 +18,7 @@ fun AddVideoStickerToSet( return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, - mapOf(pngStickerField to sticker) + mapOf(webmStickerField to sticker) ) is FileId -> data } 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 index c2d58f715a..6571ac6829 100644 --- 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 @@ -21,7 +21,7 @@ fun CreateNewAnimatedStickerSet( return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, - mapOf(pngStickerField to sticker) + mapOf(tgsStickerField to sticker) ) is FileId -> data } 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 index 0ba64a025c..c112c3498c 100644 --- 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 @@ -21,7 +21,7 @@ fun CreateNewVideoStickerSet( return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, - mapOf(pngStickerField to sticker) + mapOf(webmStickerField to sticker) ) is FileId -> data } From 00d467d0919a2c2ac16260a209c766d7cef16c85 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Feb 2022 23:25:22 +0600 Subject: [PATCH 6/7] classcasts and raw fields updates --- .../tgbotapi/extensions/utils/ClassCasts.kt | 28 +++++++++++++++++++ .../utils/extensions/raw/Sticker.kt | 21 ++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index d21790ed95..91925eee57 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -31,6 +31,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.extended.* import dev.inmo.tgbotapi.types.dice.* import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.abstracts.* +import dev.inmo.tgbotapi.types.files.sticker.* import dev.inmo.tgbotapi.types.files.sticker.Sticker import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.message.* @@ -2310,6 +2311,33 @@ inline fun TelegramMediaFile.asSticker(): Sticker? = this as? Sticker @PreviewFeature inline fun TelegramMediaFile.requireSticker(): Sticker = this as Sticker +@PreviewFeature +inline fun TelegramMediaFile.whenSimpleSticker(block: (SimpleSticker) -> T) = asSimpleSticker() ?.let(block) + +@PreviewFeature +inline fun TelegramMediaFile.asSimpleSticker(): SimpleSticker? = this as? SimpleSticker + +@PreviewFeature +inline fun TelegramMediaFile.requireSimpleSticker(): SimpleSticker = this as SimpleSticker + +@PreviewFeature +inline fun TelegramMediaFile.whenAnimatedSticker(block: (AnimatedSticker) -> T) = asAnimatedSticker() ?.let(block) + +@PreviewFeature +inline fun TelegramMediaFile.asAnimatedSticker(): AnimatedSticker? = this as? AnimatedSticker + +@PreviewFeature +inline fun TelegramMediaFile.requireAnimatedSticker(): AnimatedSticker = this as AnimatedSticker + +@PreviewFeature +inline fun TelegramMediaFile.whenVideoSticker(block: (VideoSticker) -> T) = asVideoSticker() ?.let(block) + +@PreviewFeature +inline fun TelegramMediaFile.asVideoSticker(): VideoSticker? = this as? VideoSticker + +@PreviewFeature +inline fun TelegramMediaFile.requireVideoSticker(): VideoSticker = this as VideoSticker + @PreviewFeature inline fun TelegramMediaFile.whenVideoFile(block: (VideoFile) -> T) = asVideoFile() ?.let(block) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt new file mode 100644 index 0000000000..9de78af393 --- /dev/null +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/raw/Sticker.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions.raw + +import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.files.sticker.* +import dev.inmo.tgbotapi.types.stickers.MaskPosition + +inline val Sticker.file_id: FileId + get() = fileId +inline val Sticker.file_unique_id: FileUniqueId + get() = fileUniqueId +inline val Sticker.is_animated: Boolean + get() = this is AnimatedSticker +inline val Sticker.is_video: Boolean + get() = this is VideoSticker +inline val Sticker.set_name: StickerSetName? + get() = stickerSetName +inline val Sticker.mask_position: MaskPosition? + get() = maskPosition +inline val Sticker.file_size: Long? + get() = fileSize From 054f06e18b8df1e86ad64e84c50042afb7ca37e7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Feb 2022 23:39:07 +0600 Subject: [PATCH 7/7] Update gradle.properties --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2b8cdf14cb..d54183efd5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.6.10 kotlin_coroutines_version=1.6.0 kotlin_serialisation_runtime_version=1.3.2 -klock_version=2.4.12 +klock_version=2.4.13 uuid_version=0.4.0 ktor_version=1.6.7 -micro_utils_version=0.9.4 +micro_utils_version=0.9.5 javax_activation_version=1.1.1