From 5533303d860662851e5ebaad0b163ac49733b066 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 10 Mar 2023 11:28:21 +0600 Subject: [PATCH] add setStickerEmojiList --- .../api/stickers/SetStickerEmojiList.kt | 25 ++++++++++++++ .../requests/stickers/DeleteStickerFromSet.kt | 5 +-- .../requests/stickers/SetStickerEmojiList.kt | 33 +++++++++++++++++++ .../stickers/SetStickerPositionInSet.kt | 5 +-- .../stickers/abstracts/StickerAction.kt | 8 +++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 3 ++ 6 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerEmojiList.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerEmojiList.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StickerAction.kt diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerEmojiList.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerEmojiList.kt new file mode 100644 index 0000000000..b8b1a45f5c --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/stickers/SetStickerEmojiList.kt @@ -0,0 +1,25 @@ +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.SetStickerEmojiList +import dev.inmo.tgbotapi.requests.stickers.SetStickerPositionInSet +import dev.inmo.tgbotapi.types.files.Sticker + +suspend fun TelegramBot.setStickerEmojiList( + sticker: FileId, + emojis: List +) = execute( + SetStickerEmojiList( + sticker, + emojis + ) +) + +suspend fun TelegramBot.setStickerEmojiList( + sticker: Sticker, + vararg emojis: String +) = setStickerEmojiList( + sticker.fileId, + emojis.toList() +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/DeleteStickerFromSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/DeleteStickerFromSet.kt index b6d5340fda..b9f1228b8f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/DeleteStickerFromSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/DeleteStickerFromSet.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.stickers import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.requests.stickers.abstracts.StickerAction import dev.inmo.tgbotapi.types.stickerField import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer @@ -9,8 +10,8 @@ import kotlinx.serialization.builtins.serializer @Serializable data class DeleteStickerFromSet( @SerialName(stickerField) - val sticker: FileId -) : SimpleRequest { + override val sticker: FileId +) : StickerAction { override fun method(): String = "deleteStickerFromSet" override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerEmojiList.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerEmojiList.kt new file mode 100644 index 0000000000..ef4bf80327 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerEmojiList.kt @@ -0,0 +1,33 @@ +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.OwnerStickerSetAction +import dev.inmo.tgbotapi.requests.stickers.abstracts.StickerAction +import dev.inmo.tgbotapi.requests.stickers.abstracts.StickerSetAction +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class SetStickerEmojiList ( + @SerialName(stickerField) + override val sticker: FileId, + @SerialName(emojiListField) + val emojis: List +) : StickerAction { + constructor(sticker: FileId, vararg emojis: String) : this(sticker, emojis.toList()) + + init { + require(emojis.size !in emojisInStickerLimit) { + "Emojis size should be in range $emojisInStickerLimit, but was ${emojis.size}" + } + } + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "setStickerEmojiList" +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerPositionInSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerPositionInSet.kt index 7b8bbe0599..1952c0840d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerPositionInSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/SetStickerPositionInSet.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.stickers import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.requests.stickers.abstracts.StickerAction import dev.inmo.tgbotapi.types.positionField import dev.inmo.tgbotapi.types.stickerField import kotlinx.serialization.* @@ -10,10 +11,10 @@ import kotlinx.serialization.builtins.serializer @Serializable data class SetStickerPositionInSet( @SerialName(stickerField) - val sticker: FileId, + override val sticker: FileId, @SerialName(positionField) val position: Int -) : SimpleRequest { +) : StickerAction { init { if (position < 0) { throw IllegalArgumentException("Position must be positive or 0") diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StickerAction.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StickerAction.kt new file mode 100644 index 0000000000..8fb01eb88c --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/stickers/abstracts/StickerAction.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.requests.stickers.abstracts + +import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest + +interface StickerAction : SimpleRequest { + val sticker: FileId +} 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 051774ede9..45710e163d 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 @@ -134,6 +134,8 @@ val suggestedTipAmountsLimit = 1 .. 4 val inputFieldPlaceholderLimit = 1 .. 64 +val emojisInStickerLimit = 1 .. 20 + const val botActionActualityTime: Seconds = 5 // Made as lazy for correct work in K/JS @@ -257,6 +259,7 @@ const val createsJoinRequestField = "creates_join_request" const val pendingJoinRequestCountField = "pending_join_request_count" const val memberLimitField = "member_limit" const val iconColorField = "icon_color" +const val emojiListField = "emoji_list" const val requestContactField = "request_contact" const val requestLocationField = "request_location"