mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
fixes
This commit is contained in:
parent
3c084d70e5
commit
cd62a9ef3c
@ -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<CustomEmojiId>
|
||||||
|
) = execute(
|
||||||
|
GetCustomEmojiStickers(customEmojiIds)
|
||||||
|
)
|
||||||
|
|
||||||
|
@JvmName("getCustomEmojiStickersWithStringsList")
|
||||||
|
@JsName("getCustomEmojiStickersWithStringsList")
|
||||||
|
suspend fun TelegramBot.getCustomEmojiStickers(
|
||||||
|
customEmojiIds: List<String>
|
||||||
|
) = 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))
|
@ -4,17 +4,19 @@ import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
|||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
import dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
||||||
import dev.inmo.tgbotapi.types.files.StickerSerializer
|
import dev.inmo.tgbotapi.types.files.StickerSerializer
|
||||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
|
||||||
|
internal val getCustomEmojiStickersResultSerializer = ListSerializer(StickerSerializer) as DeserializationStrategy<List<CustomEmojiSticker>>
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetCustomEmojiStickers(
|
data class GetCustomEmojiStickers(
|
||||||
@SerialName(customEmojiIdsField)
|
@SerialName(customEmojiIdsField)
|
||||||
val customEmojiIds: List<CustomEmojiId>
|
val customEmojiIds: List<CustomEmojiId>
|
||||||
): SimpleRequest<CustomEmojiSticker> {
|
): SimpleRequest<List<CustomEmojiSticker>> {
|
||||||
override fun method(): String = "getCustomEmojiStickers"
|
override fun method(): String = "getCustomEmojiStickers"
|
||||||
override val resultDeserializer: DeserializationStrategy<CustomEmojiSticker>
|
override val resultDeserializer: DeserializationStrategy<List<CustomEmojiSticker>>
|
||||||
get() = StickerSerializer as DeserializationStrategy<CustomEmojiSticker>
|
get() = getCustomEmojiStickersResultSerializer
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package dev.inmo.tgbotapi.requests.get
|
package dev.inmo.tgbotapi.requests.get
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||||
|
import dev.inmo.tgbotapi.types.nameField
|
||||||
import dev.inmo.tgbotapi.types.stickerSetNameField
|
import dev.inmo.tgbotapi.types.stickerSetNameField
|
||||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetStickerSet(
|
data class GetStickerSet(
|
||||||
@SerialName(stickerSetNameField)
|
@SerialName(nameField)
|
||||||
val name: String
|
val name: String
|
||||||
): SimpleRequest<StickerSet> {
|
): SimpleRequest<StickerSet> {
|
||||||
override fun method(): String = "getStickerSet"
|
override fun method(): String = "getStickerSet"
|
||||||
|
@ -68,8 +68,8 @@ sealed interface StickerType {
|
|||||||
override fun deserialize(decoder: Decoder): StickerType {
|
override fun deserialize(decoder: Decoder): StickerType {
|
||||||
return when (val type = decoder.decodeString()) {
|
return when (val type = decoder.decodeString()) {
|
||||||
Regular.type -> Regular
|
Regular.type -> Regular
|
||||||
Mask.type -> Regular
|
Mask.type -> Mask
|
||||||
CustomEmoji.type -> Regular
|
CustomEmoji.type -> CustomEmoji
|
||||||
else -> Unknown(type)
|
else -> Unknown(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEn
|
|||||||
is UnderlineTextSource -> RawMessageEntity("underline", offset, length)
|
is UnderlineTextSource -> RawMessageEntity("underline", offset, length)
|
||||||
is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length)
|
is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length)
|
||||||
is SpoilerTextSource -> RawMessageEntity("spoiler", 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
|
is RegularTextSource -> null
|
||||||
}
|
}
|
||||||
) + if (this is MultilevelTextSource) {
|
) + if (this is MultilevelTextSource) {
|
||||||
|
@ -36,7 +36,7 @@ sealed interface MultilevelTextSource : TextSource {
|
|||||||
val subsources: List<TextSource>
|
val subsources: List<TextSource>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
|
fun List<TextSource>.splitForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
@ -70,13 +70,27 @@ fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = n
|
|||||||
* This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with
|
* This method will prepare [TextSource]s list for messages. Remember, that first part will be separated with
|
||||||
* [captionLength] and all others with
|
* [captionLength] and all others with
|
||||||
*/
|
*/
|
||||||
fun List<TextSource>.separateForCaption(): List<List<TextSource>> {
|
fun List<TextSource>.splitForCaption(): List<List<TextSource>> {
|
||||||
val captionPart = separateForMessage(captionLength, 1).first()
|
val captionPart = splitForMessage(captionLength, 1).first()
|
||||||
return listOf(captionPart) + minus(captionPart).separateForMessage(textLength)
|
return listOf(captionPart) + minus(captionPart).splitForMessage(textLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will prepare [TextSource]s list for messages with [textLength]
|
* This method will prepare [TextSource]s list for messages with [textLength]
|
||||||
*/
|
*/
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
inline fun List<TextSource>.separateForText(): List<List<TextSource>> = separateForMessage(textLength)
|
inline fun List<TextSource>.splitForText(): List<List<TextSource>> = splitForMessage(textLength)
|
||||||
|
|
||||||
|
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> = 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<TextSource>.separateForCaption(): List<List<TextSource>> = splitForCaption()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will prepare [TextSource]s list for messages with [textLength]
|
||||||
|
*/
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun List<TextSource>.separateForText(): List<List<TextSource>> = splitForText()
|
||||||
|
Loading…
Reference in New Issue
Block a user