diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetCustomEmojiStickers.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetCustomEmojiStickers.kt new file mode 100644 index 0000000000..60e3784a8d --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/get/GetCustomEmojiStickers.kt @@ -0,0 +1,37 @@ +package dev.inmo.tgbotapi.extensions.api.get + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.get.GetCustomEmojiStickers +import dev.inmo.tgbotapi.requests.get.GetStickerSet +import dev.inmo.tgbotapi.types.CustomEmojiId +import dev.inmo.tgbotapi.types.files.Sticker +import kotlin.js.JsName +import kotlin.jvm.JvmName + +suspend fun TelegramBot.getCustomEmojiStickers( + customEmojiIds: List +) = execute( + GetCustomEmojiStickers(customEmojiIds) +) + +@JvmName("getCustomEmojiStickersWithStringsList") +@JsName("getCustomEmojiStickersWithStringsList") +suspend fun TelegramBot.getCustomEmojiStickers( + customEmojiIds: List +) = getCustomEmojiStickers(customEmojiIds.map(::CustomEmojiId)) + +suspend fun TelegramBot.getCustomEmojiStickerOrNull( + customEmojiId: CustomEmojiId +) = getCustomEmojiStickers(listOf(customEmojiId)).firstOrNull() + +suspend fun TelegramBot.getCustomEmojiStickerOrThrow( + customEmojiId: CustomEmojiId +) = getCustomEmojiStickers(listOf(customEmojiId)).first() + +suspend fun TelegramBot.getCustomEmojiStickerOrNull( + customEmojiId: String +) = getCustomEmojiStickerOrNull(CustomEmojiId(customEmojiId)) + +suspend fun TelegramBot.getCustomEmojiStickerOrThrow( + customEmojiId: String +) = getCustomEmojiStickerOrThrow(CustomEmojiId(customEmojiId)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetCustomEmojiStickers.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetCustomEmojiStickers.kt index 3d144b32f8..8cba482df8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetCustomEmojiStickers.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetCustomEmojiStickers.kt @@ -4,17 +4,19 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.CustomEmojiSticker import dev.inmo.tgbotapi.types.files.StickerSerializer -import dev.inmo.tgbotapi.types.stickers.StickerSet import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer + +internal val getCustomEmojiStickersResultSerializer = ListSerializer(StickerSerializer) as DeserializationStrategy> @Serializable data class GetCustomEmojiStickers( @SerialName(customEmojiIdsField) val customEmojiIds: List -): SimpleRequest { +): SimpleRequest> { override fun method(): String = "getCustomEmojiStickers" - override val resultDeserializer: DeserializationStrategy - get() = StickerSerializer as DeserializationStrategy + override val resultDeserializer: DeserializationStrategy> + get() = getCustomEmojiStickersResultSerializer override val requestSerializer: SerializationStrategy<*> get() = serializer() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetStickerSet.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetStickerSet.kt index a9262458ef..2303e7f920 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetStickerSet.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/get/GetStickerSet.kt @@ -1,13 +1,14 @@ package dev.inmo.tgbotapi.requests.get import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.nameField import dev.inmo.tgbotapi.types.stickerSetNameField import dev.inmo.tgbotapi.types.stickers.StickerSet import kotlinx.serialization.* @Serializable data class GetStickerSet( - @SerialName(stickerSetNameField) + @SerialName(nameField) val name: String ): SimpleRequest { override fun method(): String = "getStickerSet" 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 57efb1874d..103f327380 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 @@ -68,8 +68,8 @@ sealed interface StickerType { override fun deserialize(decoder: Decoder): StickerType { return when (val type = decoder.decodeString()) { Regular.type -> Regular - Mask.type -> Regular - CustomEmoji.type -> Regular + Mask.type -> Mask + CustomEmoji.type -> CustomEmoji else -> Unknown(type) } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt index 13ef5a42f8..8d4e49fe0a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt @@ -161,7 +161,7 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List RawMessageEntity("underline", offset, length) is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length) is SpoilerTextSource -> RawMessageEntity("spoiler", offset, length) - is CustomEmojiTextSource -> RawMessageEntity("custom_emoji", offset, length) + is CustomEmojiTextSource -> RawMessageEntity("custom_emoji", offset, length, custom_emoji_id = customEmojiId) is RegularTextSource -> null } ) + if (this is MultilevelTextSource) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextSource.kt index 5a0fc2b1ef..4a44363d69 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/textsources/TextSource.kt @@ -36,7 +36,7 @@ sealed interface MultilevelTextSource : TextSource { val subsources: List } -fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { +fun List.splitForMessage(limit: IntRange, numberOfParts: Int? = null): List> { if (isEmpty()) { return emptyList() } @@ -70,13 +70,27 @@ fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = n * This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with * [captionLength] and all others with */ -fun List.separateForCaption(): List> { - val captionPart = separateForMessage(captionLength, 1).first() - return listOf(captionPart) + minus(captionPart).separateForMessage(textLength) +fun List.splitForCaption(): List> { + val captionPart = splitForMessage(captionLength, 1).first() + return listOf(captionPart) + minus(captionPart).splitForMessage(textLength) } /** * This method will prepare [TextSource]s list for messages with [textLength] */ @Suppress("NOTHING_TO_INLINE") -inline fun List.separateForText(): List> = separateForMessage(textLength) +inline fun List.splitForText(): List> = splitForMessage(textLength) + +fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> = splitForMessage(limit, numberOfParts) + +/** + * This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with + * [captionLength] and all others with + */ +fun List.separateForCaption(): List> = splitForCaption() + +/** + * This method will prepare [TextSource]s list for messages with [textLength] + */ +@Suppress("NOTHING_TO_INLINE") +inline fun List.separateForText(): List> = splitForText()