mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-12-29 09:29:23 +00:00
Compare commits
7 Commits
3fc1058491
...
3.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| cd62a9ef3c | |||
| 3c084d70e5 | |||
| 2611d4ecc1 | |||
| b4d853dfa0 | |||
| 5044075adf | |||
| 5f2660b804 | |||
| c72dccc0f9 |
@@ -2,8 +2,14 @@
|
||||
|
||||
## 3.1.0
|
||||
|
||||
**This update contains including of Bot API 6.2**
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `2.0.3` -> `2.1.0`
|
||||
* `MicroUtils`: `0.12.0` -> `0.12.1`
|
||||
* `Core`:
|
||||
* Add support of `custom emoji`s
|
||||
* Add support of `sticker_type`
|
||||
|
||||
## 3.0.2
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# TelegramBotAPI [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [](https://core.telegram.org/bots/api-changelog#june-20-2022)
|
||||
# TelegramBotAPI [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [](https://core.telegram.org/bots/api-changelog#august-12-2022)
|
||||
|
||||
| Docs | [](https://tgbotapi.inmo.dev/index.html) [](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
||||
|:---:|:---:|
|
||||
|
||||
@@ -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))
|
||||
@@ -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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewMaskAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskAnimatedStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskAnimatedStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewMaskAnimatedStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskAnimatedStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskAnimatedStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskAnimatedStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
@@ -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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewMaskStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewMaskStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
@@ -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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewMaskVideoStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskVideoStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskVideoStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = execute(
|
||||
CreateNewMaskVideoStickerSet(userId, name, title, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewMaskVideoStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskVideoStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewMaskVideoStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
) = createNewMaskVideoStickerSet(
|
||||
user.id, name, title, sticker, emojis, maskPosition
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewRegularAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularAnimatedStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularAnimatedStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewRegularAnimatedStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = createNewRegularAnimatedStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularAnimatedStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = createNewRegularAnimatedStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewRegularStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewRegularStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = createNewRegularStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = createNewRegularStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
@@ -0,0 +1,50 @@
|
||||
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.*
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
suspend fun TelegramBot.createNewRegularVideoStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularVideoStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularVideoStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = execute(
|
||||
CreateNewRegularVideoStickerSet(userId, name, title, sticker, emojis)
|
||||
)
|
||||
|
||||
|
||||
suspend fun TelegramBot.createNewRegularVideoStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: FileId,
|
||||
emojis: String
|
||||
) = createNewRegularVideoStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.createNewRegularVideoStickerSet(
|
||||
user: CommonUser,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String
|
||||
) = createNewRegularVideoStickerSet(
|
||||
user.id, name, title, sticker, emojis
|
||||
)
|
||||
@@ -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<List<CustomEmojiSticker>>
|
||||
|
||||
@Serializable
|
||||
data class GetCustomEmojiStickers(
|
||||
@SerialName(customEmojiIdsField)
|
||||
val customEmojiIds: List<CustomEmojiId>
|
||||
): SimpleRequest<CustomEmojiSticker> {
|
||||
): SimpleRequest<List<CustomEmojiSticker>> {
|
||||
override fun method(): String = "getCustomEmojiStickers"
|
||||
override val resultDeserializer: DeserializationStrategy<CustomEmojiSticker>
|
||||
get() = StickerSerializer as DeserializationStrategy<CustomEmojiSticker>
|
||||
override val resultDeserializer: DeserializationStrategy<List<CustomEmojiSticker>>
|
||||
get() = getCustomEmojiStickersResultSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
@@ -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<StickerSet> {
|
||||
override fun method(): String = "getStickerSet"
|
||||
|
||||
@@ -8,26 +8,8 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun CreateNewAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
containsMasks: Boolean? = null,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> {
|
||||
val data = CreateNewAnimatedStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition)
|
||||
return when (sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(tgsStickerField to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@Deprecated("Use CreateNewStickerSet class instead")
|
||||
data class CreateNewAnimatedStickerSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
|
||||
@@ -8,36 +8,8 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun CreateNewStaticStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
containsMasks: Boolean? = null,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> {
|
||||
val data = CreateNewStaticStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition)
|
||||
return when (sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(pngStickerField to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
fun CreateNewStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
containsMasks: Boolean? = null,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> = CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
|
||||
|
||||
@Serializable
|
||||
@Deprecated("Use CreateNewStickerSet class instead")
|
||||
data class CreateNewStaticStickerSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
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.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
internal 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
|
||||
): Request<Boolean> {
|
||||
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) {
|
||||
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()
|
||||
)
|
||||
} else {
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@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")
|
||||
}
|
||||
}
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "createNewStickerSet"
|
||||
}
|
||||
@@ -8,26 +8,8 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun CreateNewVideoStickerSet(
|
||||
userId: UserId,
|
||||
linkName: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
containsMasks: Boolean? = null,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> {
|
||||
val data = CreateNewVideoStickerSet(userId, linkName, title, emojis, sticker as? FileId, containsMasks, maskPosition)
|
||||
return when (sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(webmStickerField to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@Deprecated("Use CreateNewStickerSet class instead")
|
||||
data class CreateNewVideoStickerSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
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<Boolean> = CreateNewStickerSet(
|
||||
userId,
|
||||
name,
|
||||
title,
|
||||
emojis,
|
||||
StickerType.Regular,
|
||||
pngSticker = sticker
|
||||
)
|
||||
|
||||
fun CreateNewRegularVideoStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String
|
||||
): Request<Boolean> = CreateNewStickerSet(
|
||||
userId,
|
||||
name,
|
||||
title,
|
||||
emojis,
|
||||
StickerType.Regular,
|
||||
webmSticker = sticker
|
||||
)
|
||||
|
||||
fun CreateNewRegularAnimatedStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String
|
||||
): Request<Boolean> = CreateNewStickerSet(
|
||||
userId,
|
||||
name,
|
||||
title,
|
||||
emojis,
|
||||
StickerType.Regular,
|
||||
tgsSticker = sticker
|
||||
)
|
||||
|
||||
|
||||
fun CreateNewMaskStickerSet(
|
||||
userId: UserId,
|
||||
name: String,
|
||||
title: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition
|
||||
): Request<Boolean> = 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<Boolean> = 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<Boolean> = CreateNewStickerSet(
|
||||
userId,
|
||||
name,
|
||||
title,
|
||||
emojis,
|
||||
StickerType.Mask,
|
||||
tgsSticker = sticker,
|
||||
maskPosition = maskPosition
|
||||
)
|
||||
@@ -0,0 +1,80 @@
|
||||
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<Boolean> = 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<Boolean> = 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<Boolean> = 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<Boolean> = CreateNewStickerSet(
|
||||
userId,
|
||||
name,
|
||||
title,
|
||||
emojis,
|
||||
if (containsMasks == true) StickerType.Mask else StickerType.Regular,
|
||||
tgsSticker = sticker,
|
||||
maskPosition = maskPosition
|
||||
)
|
||||
@@ -59,6 +59,8 @@ sealed interface StickerType {
|
||||
object Mask : StickerType { override val type: String = "mask" }
|
||||
@Serializable
|
||||
object CustomEmoji : StickerType { override val type: String = "custom_emoji" }
|
||||
@Serializable
|
||||
data class Unknown(override val type: String = "custom_emoji") : StickerType
|
||||
|
||||
object Serializer : KSerializer<StickerType> {
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
@@ -66,9 +68,9 @@ sealed interface StickerType {
|
||||
override fun deserialize(decoder: Decoder): StickerType {
|
||||
return when (val type = decoder.decodeString()) {
|
||||
Regular.type -> Regular
|
||||
Mask.type -> Regular
|
||||
CustomEmoji.type -> Regular
|
||||
else -> error("Unknown type of emoji $type")
|
||||
Mask.type -> Mask
|
||||
CustomEmoji.type -> CustomEmoji
|
||||
else -> Unknown(type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
@RiskFeature("This class is used for serialization/deserialization of Sticker interface")
|
||||
@@ -44,7 +46,8 @@ object StickerSerializer : KSerializer<Sticker> {
|
||||
override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): Sticker {
|
||||
val surrogate = StickerSurrogate.serializer().deserialize(decoder)
|
||||
val json = JsonElement.serializer().deserialize(decoder)
|
||||
val surrogate = nonstrictJsonFormat.decodeFromJsonElement(StickerSurrogate.serializer(), json)
|
||||
|
||||
return when (surrogate.type) {
|
||||
StickerType.Regular -> when {
|
||||
@@ -82,19 +85,41 @@ object StickerSerializer : KSerializer<Sticker> {
|
||||
surrogate.file_size
|
||||
)
|
||||
}
|
||||
StickerType.Mask -> MaskSticker(
|
||||
surrogate.file_id,
|
||||
surrogate.file_unique_id,
|
||||
surrogate.width,
|
||||
surrogate.height,
|
||||
surrogate.mask_position ?: error("For mask stickers field mask_position should be presented"),
|
||||
surrogate.is_animated == true,
|
||||
surrogate.is_video == true,
|
||||
surrogate.thumb,
|
||||
surrogate.emoji,
|
||||
surrogate.set_name,
|
||||
surrogate.file_size
|
||||
)
|
||||
StickerType.Mask -> when {
|
||||
surrogate.is_animated == true -> MaskAnimatedSticker(
|
||||
surrogate.file_id,
|
||||
surrogate.file_unique_id,
|
||||
surrogate.width,
|
||||
surrogate.height,
|
||||
surrogate.mask_position ?: error("For mask stickers field mask_position should be presented"),
|
||||
surrogate.thumb,
|
||||
surrogate.emoji,
|
||||
surrogate.set_name,
|
||||
surrogate.file_size
|
||||
)
|
||||
surrogate.is_video == true -> MaskVideoSticker(
|
||||
surrogate.file_id,
|
||||
surrogate.file_unique_id,
|
||||
surrogate.width,
|
||||
surrogate.height,
|
||||
surrogate.mask_position ?: error("For mask stickers field mask_position should be presented"),
|
||||
surrogate.thumb,
|
||||
surrogate.emoji,
|
||||
surrogate.set_name,
|
||||
surrogate.file_size
|
||||
)
|
||||
else -> MaskSimpleSticker(
|
||||
surrogate.file_id,
|
||||
surrogate.file_unique_id,
|
||||
surrogate.width,
|
||||
surrogate.height,
|
||||
surrogate.mask_position ?: error("For mask stickers field mask_position should be presented"),
|
||||
surrogate.thumb,
|
||||
surrogate.emoji,
|
||||
surrogate.set_name,
|
||||
surrogate.file_size
|
||||
)
|
||||
}
|
||||
StickerType.CustomEmoji -> when {
|
||||
surrogate.is_animated == true -> CustomEmojiAnimatedSticker(
|
||||
surrogate.file_id,
|
||||
@@ -130,6 +155,17 @@ object StickerSerializer : KSerializer<Sticker> {
|
||||
surrogate.file_size
|
||||
)
|
||||
}
|
||||
is StickerType.Unknown -> UnknownSticker(
|
||||
surrogate.file_id,
|
||||
surrogate.file_unique_id,
|
||||
surrogate.width,
|
||||
surrogate.height,
|
||||
surrogate.thumb,
|
||||
surrogate.emoji,
|
||||
surrogate.set_name,
|
||||
surrogate.file_size,
|
||||
json
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,48 +175,22 @@ object StickerSerializer : KSerializer<Sticker> {
|
||||
|
||||
}
|
||||
|
||||
@Serializable(StickerSerializer::class)
|
||||
@Serializable
|
||||
sealed interface VideoSticker : Sticker {
|
||||
override val isVideo: Boolean
|
||||
get() = true
|
||||
}
|
||||
@Serializable(StickerSerializer::class)
|
||||
@Serializable
|
||||
sealed interface AnimatedSticker : Sticker {
|
||||
override val isAnimated: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
@Serializable(StickerSerializer::class)
|
||||
@Serializable
|
||||
sealed interface RegularSticker : Sticker {
|
||||
val premiumAnimationFile: File?
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MaskSticker(
|
||||
@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(maskPositionField)
|
||||
val maskPosition: MaskPosition,
|
||||
@SerialName(isAnimatedField)
|
||||
override val isAnimated: Boolean,
|
||||
@SerialName(isVideoField)
|
||||
override val isVideo: Boolean,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null,
|
||||
@SerialName(emojiField)
|
||||
override val emoji: String? = null,
|
||||
@SerialName(stickerSetNameField)
|
||||
override val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
) : Sticker
|
||||
|
||||
@Serializable
|
||||
data class RegularSimpleSticker(
|
||||
@SerialName(fileIdField)
|
||||
@@ -247,7 +257,76 @@ data class RegularVideoSticker(
|
||||
override val fileSize: Long? = null,
|
||||
) : RegularSticker, VideoSticker
|
||||
|
||||
@Serializable(StickerSerializer::class)
|
||||
|
||||
@Serializable
|
||||
sealed interface MaskSticker : Sticker {
|
||||
val maskPosition: MaskPosition
|
||||
}
|
||||
@Serializable
|
||||
data class MaskSimpleSticker(
|
||||
@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(maskPositionField)
|
||||
override val maskPosition: MaskPosition,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null,
|
||||
@SerialName(emojiField)
|
||||
override val emoji: String? = null,
|
||||
@SerialName(stickerSetNameField)
|
||||
override val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
) : MaskSticker
|
||||
@Serializable
|
||||
data class MaskAnimatedSticker(
|
||||
@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(maskPositionField)
|
||||
override val maskPosition: MaskPosition,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null,
|
||||
@SerialName(emojiField)
|
||||
override val emoji: String? = null,
|
||||
@SerialName(stickerSetNameField)
|
||||
override val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
) : MaskSticker, AnimatedSticker
|
||||
@Serializable
|
||||
data class MaskVideoSticker(
|
||||
@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(maskPositionField)
|
||||
override val maskPosition: MaskPosition,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null,
|
||||
@SerialName(emojiField)
|
||||
override val emoji: String? = null,
|
||||
@SerialName(stickerSetNameField)
|
||||
override val stickerSetName: StickerSetName? = null,
|
||||
@SerialName(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
) : MaskSticker, VideoSticker
|
||||
|
||||
@Serializable
|
||||
sealed interface CustomEmojiSticker : Sticker {
|
||||
val customEmojiId: CustomEmojiId
|
||||
}
|
||||
@@ -315,3 +394,24 @@ data class CustomEmojiVideoSticker(
|
||||
@SerialName(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
) : CustomEmojiSticker, VideoSticker
|
||||
|
||||
@Serializable
|
||||
data class UnknownSticker(
|
||||
@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(fileSizeField)
|
||||
override val fileSize: Long? = null,
|
||||
val raw: JsonElement
|
||||
) : Sticker
|
||||
|
||||
@@ -161,7 +161,7 @@ internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEn
|
||||
is UnderlineTextSource -> 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) {
|
||||
|
||||
@@ -36,7 +36,7 @@ sealed interface MultilevelTextSource : 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()) {
|
||||
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
|
||||
* [captionLength] and all others with
|
||||
*/
|
||||
fun List<TextSource>.separateForCaption(): List<List<TextSource>> {
|
||||
val captionPart = separateForMessage(captionLength, 1).first()
|
||||
return listOf(captionPart) + minus(captionPart).separateForMessage(textLength)
|
||||
fun List<TextSource>.splitForCaption(): List<List<TextSource>> {
|
||||
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<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()
|
||||
|
||||
@@ -2,86 +2,297 @@ package dev.inmo.tgbotapi.types.stickers
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
data class SurrogateStickerSet(
|
||||
val name: String,
|
||||
val title: String,
|
||||
val sticker_type: StickerType,
|
||||
val is_animated: Boolean? = false,
|
||||
val is_video: Boolean? = false,
|
||||
val stickers: List<@Serializable(StickerSerializer::class) Sticker> = emptyList(),
|
||||
val thumb: PhotoSize? = null
|
||||
)
|
||||
|
||||
@Serializable(StickerSet.Serializer::class)
|
||||
sealed interface StickerSet {
|
||||
@SerialName(nameField)
|
||||
val name: String
|
||||
@SerialName(titleField)
|
||||
val title: String
|
||||
@SerialName(stickerTypeField)
|
||||
val stickerType: StickerType
|
||||
@SerialName(stickersField)
|
||||
val stickers: List<Sticker>
|
||||
@SerialName(isAnimatedField)
|
||||
val isAnimated: Boolean
|
||||
@SerialName(isVideoField)
|
||||
get() = false
|
||||
val isVideo: Boolean
|
||||
@SerialName(containsMasksField)
|
||||
get() = false
|
||||
val thumb: PhotoSize?
|
||||
@Deprecated("Will be removed soon due to its redundancy")
|
||||
val containsMasks: Boolean
|
||||
get() = this is MaskStickerSet
|
||||
@SerialName(thumbField)
|
||||
val thumb: PhotoSize?
|
||||
|
||||
object Serializer : KSerializer<StickerSet> {
|
||||
override val descriptor: SerialDescriptor = JsonElement.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): StickerSet {
|
||||
val json = JsonElement.serializer().deserialize(decoder)
|
||||
val surrogate = nonstrictJsonFormat.decodeFromJsonElement(SurrogateStickerSet.serializer(), json)
|
||||
|
||||
return when (surrogate.sticker_type) {
|
||||
StickerType.CustomEmoji -> when {
|
||||
surrogate.is_animated == true -> CustomEmojiAnimatedStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<CustomEmojiAnimatedSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
surrogate.is_video == true -> CustomEmojiVideoStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<CustomEmojiVideoSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
else -> CustomEmojiSimpleStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<CustomEmojiSimpleSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
}
|
||||
StickerType.Mask -> when {
|
||||
surrogate.is_animated == true -> MaskAnimatedStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<MaskAnimatedSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
surrogate.is_video == true -> MaskVideoStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<MaskVideoSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
else -> MaskSimpleStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<MaskSimpleSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
}
|
||||
StickerType.Regular -> when {
|
||||
surrogate.is_animated == true -> RegularAnimatedStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<RegularAnimatedSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
surrogate.is_video == true -> RegularVideoStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<RegularVideoSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
else -> RegularSimpleStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<RegularSimpleSticker>(),
|
||||
surrogate.thumb
|
||||
)
|
||||
}
|
||||
is StickerType.Unknown -> UnknownStickerSet(
|
||||
surrogate.name,
|
||||
surrogate.title,
|
||||
surrogate.stickers.filterIsInstance<RegularSimpleSticker>(),
|
||||
surrogate.sticker_type,
|
||||
surrogate.thumb,
|
||||
json
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: StickerSet) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class RegularStickerSet(
|
||||
sealed interface AnimatedStickerSet : StickerSet {
|
||||
override val isAnimated: Boolean
|
||||
get() = true
|
||||
}
|
||||
@Serializable
|
||||
sealed interface VideoStickerSet : StickerSet {
|
||||
override val isVideo: Boolean
|
||||
get() = true
|
||||
}
|
||||
@Serializable
|
||||
sealed interface RegularStickerSet : StickerSet
|
||||
@Serializable
|
||||
sealed interface MaskStickerSet : StickerSet
|
||||
@Serializable
|
||||
sealed interface CustomEmojiStickerSet : StickerSet
|
||||
|
||||
@Serializable
|
||||
data class RegularSimpleStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<RegularSticker>,
|
||||
@SerialName(isAnimatedField)
|
||||
override val isAnimated: Boolean = false,
|
||||
@SerialName(isVideoField)
|
||||
override val isVideo: Boolean = false,
|
||||
override val stickers: List<RegularSimpleSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : StickerSet {
|
||||
) : RegularStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Regular
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MaskStickerSet(
|
||||
data class RegularAnimatedStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<MaskSticker>,
|
||||
@SerialName(isAnimatedField)
|
||||
override val isAnimated: Boolean = false,
|
||||
@SerialName(isVideoField)
|
||||
override val isVideo: Boolean = false,
|
||||
override val stickers: List<RegularAnimatedSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : StickerSet {
|
||||
) : RegularStickerSet, AnimatedStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Regular
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class RegularVideoStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<RegularVideoSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : RegularStickerSet, VideoStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Regular
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MaskSimpleStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<MaskSimpleSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : MaskStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Mask
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CustomEmojiStickerSet(
|
||||
data class MaskAnimatedStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<CustomEmojiSticker>,
|
||||
@SerialName(isAnimatedField)
|
||||
override val isAnimated: Boolean = false,
|
||||
@SerialName(isVideoField)
|
||||
override val isVideo: Boolean = false,
|
||||
override val stickers: List<MaskAnimatedSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : StickerSet {
|
||||
) : MaskStickerSet, AnimatedStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Mask
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class MaskVideoStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<MaskVideoSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : MaskStickerSet, VideoStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.Mask
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CustomEmojiSimpleStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<CustomEmojiSimpleSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : CustomEmojiStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.CustomEmoji
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CustomEmojiAnimatedStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<CustomEmojiAnimatedSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : CustomEmojiStickerSet, AnimatedStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.CustomEmoji
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CustomEmojiVideoStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<CustomEmojiVideoSticker>,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null
|
||||
) : CustomEmojiStickerSet, VideoStickerSet {
|
||||
@SerialName(stickerTypeField)
|
||||
@EncodeDefault
|
||||
override val stickerType: StickerType = StickerType.CustomEmoji
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class UnknownStickerSet(
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(stickersField)
|
||||
override val stickers: List<Sticker>,
|
||||
@SerialName(stickerTypeField)
|
||||
override val stickerType: StickerType,
|
||||
@SerialName(thumbField)
|
||||
override val thumb: PhotoSize? = null,
|
||||
val raw: JsonElement
|
||||
) : CustomEmojiStickerSet, VideoStickerSet
|
||||
|
||||
@@ -167,18 +167,30 @@ import dev.inmo.tgbotapi.types.dice.SlotMachineDiceAnimationType
|
||||
import dev.inmo.tgbotapi.types.files.AnimatedSticker
|
||||
import dev.inmo.tgbotapi.types.files.AnimationFile
|
||||
import dev.inmo.tgbotapi.types.files.AudioFile
|
||||
import dev.inmo.tgbotapi.types.files.CustomEmojiAnimatedSticker
|
||||
import dev.inmo.tgbotapi.types.files.CustomEmojiSimpleSticker
|
||||
import dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
||||
import dev.inmo.tgbotapi.types.files.CustomEmojiVideoSticker
|
||||
import dev.inmo.tgbotapi.types.files.DocumentFile
|
||||
import dev.inmo.tgbotapi.types.files.File
|
||||
import dev.inmo.tgbotapi.types.files.MaskAnimatedSticker
|
||||
import dev.inmo.tgbotapi.types.files.MaskSimpleSticker
|
||||
import dev.inmo.tgbotapi.types.files.MaskSticker
|
||||
import dev.inmo.tgbotapi.types.files.MaskVideoSticker
|
||||
import dev.inmo.tgbotapi.types.files.MimedMediaFile
|
||||
import dev.inmo.tgbotapi.types.files.PassportFile
|
||||
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||
import dev.inmo.tgbotapi.types.files.PhotoSize
|
||||
import dev.inmo.tgbotapi.types.files.PlayableMediaFile
|
||||
import dev.inmo.tgbotapi.types.files.SimpleSticker
|
||||
import dev.inmo.tgbotapi.types.files.RegularAnimatedSticker
|
||||
import dev.inmo.tgbotapi.types.files.RegularSimpleSticker
|
||||
import dev.inmo.tgbotapi.types.files.RegularSticker
|
||||
import dev.inmo.tgbotapi.types.files.RegularVideoSticker
|
||||
import dev.inmo.tgbotapi.types.files.SizedMediaFile
|
||||
import dev.inmo.tgbotapi.types.files.Sticker
|
||||
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
|
||||
import dev.inmo.tgbotapi.types.files.ThumbedMediaFile
|
||||
import dev.inmo.tgbotapi.types.files.UnknownSticker
|
||||
import dev.inmo.tgbotapi.types.files.VideoFile
|
||||
import dev.inmo.tgbotapi.types.files.VideoNoteFile
|
||||
import dev.inmo.tgbotapi.types.files.VideoSticker
|
||||
@@ -2267,14 +2279,14 @@ public inline fun TelegramMediaFile.stickerOrThrow(): Sticker = this as
|
||||
public inline fun <T> TelegramMediaFile.ifSticker(block: (Sticker) -> T): T? = stickerOrNull()
|
||||
?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.simpleStickerOrNull(): SimpleSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.SimpleSticker
|
||||
public inline fun TelegramMediaFile.videoStickerOrNull(): VideoSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.VideoSticker
|
||||
|
||||
public inline fun TelegramMediaFile.simpleStickerOrThrow(): SimpleSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.SimpleSticker
|
||||
public inline fun TelegramMediaFile.videoStickerOrThrow(): VideoSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.VideoSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifSimpleSticker(block: (SimpleSticker) -> T): T? =
|
||||
simpleStickerOrNull() ?.let(block)
|
||||
public inline fun <T> TelegramMediaFile.ifVideoSticker(block: (VideoSticker) -> T): T? =
|
||||
videoStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.animatedStickerOrNull(): AnimatedSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.AnimatedSticker
|
||||
@@ -2285,14 +2297,126 @@ public inline fun TelegramMediaFile.animatedStickerOrThrow(): AnimatedSticker =
|
||||
public inline fun <T> TelegramMediaFile.ifAnimatedSticker(block: (AnimatedSticker) -> T): T? =
|
||||
animatedStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.videoStickerOrNull(): VideoSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.VideoSticker
|
||||
public inline fun TelegramMediaFile.regularStickerOrNull(): RegularSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.RegularSticker
|
||||
|
||||
public inline fun TelegramMediaFile.videoStickerOrThrow(): VideoSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.VideoSticker
|
||||
public inline fun TelegramMediaFile.regularStickerOrThrow(): RegularSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.RegularSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifVideoSticker(block: (VideoSticker) -> T): T? =
|
||||
videoStickerOrNull() ?.let(block)
|
||||
public inline fun <T> TelegramMediaFile.ifRegularSticker(block: (RegularSticker) -> T): T? =
|
||||
regularStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.regularSimpleStickerOrNull(): RegularSimpleSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.RegularSimpleSticker
|
||||
|
||||
public inline fun TelegramMediaFile.regularSimpleStickerOrThrow(): RegularSimpleSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.RegularSimpleSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifRegularSimpleSticker(block: (RegularSimpleSticker) -> T):
|
||||
T? = regularSimpleStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.regularAnimatedStickerOrNull(): RegularAnimatedSticker? = this
|
||||
as? dev.inmo.tgbotapi.types.files.RegularAnimatedSticker
|
||||
|
||||
public inline fun TelegramMediaFile.regularAnimatedStickerOrThrow(): RegularAnimatedSticker = this
|
||||
as dev.inmo.tgbotapi.types.files.RegularAnimatedSticker
|
||||
|
||||
public inline fun <T>
|
||||
TelegramMediaFile.ifRegularAnimatedSticker(block: (RegularAnimatedSticker) -> T): T? =
|
||||
regularAnimatedStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.regularVideoStickerOrNull(): RegularVideoSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.RegularVideoSticker
|
||||
|
||||
public inline fun TelegramMediaFile.regularVideoStickerOrThrow(): RegularVideoSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.RegularVideoSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifRegularVideoSticker(block: (RegularVideoSticker) -> T): T?
|
||||
= regularVideoStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.maskStickerOrNull(): MaskSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.MaskSticker
|
||||
|
||||
public inline fun TelegramMediaFile.maskStickerOrThrow(): MaskSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.MaskSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifMaskSticker(block: (MaskSticker) -> T): T? =
|
||||
maskStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.maskSimpleStickerOrNull(): MaskSimpleSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.MaskSimpleSticker
|
||||
|
||||
public inline fun TelegramMediaFile.maskSimpleStickerOrThrow(): MaskSimpleSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.MaskSimpleSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifMaskSimpleSticker(block: (MaskSimpleSticker) -> T): T? =
|
||||
maskSimpleStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.maskAnimatedStickerOrNull(): MaskAnimatedSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.MaskAnimatedSticker
|
||||
|
||||
public inline fun TelegramMediaFile.maskAnimatedStickerOrThrow(): MaskAnimatedSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.MaskAnimatedSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifMaskAnimatedSticker(block: (MaskAnimatedSticker) -> T): T?
|
||||
= maskAnimatedStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.maskVideoStickerOrNull(): MaskVideoSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.MaskVideoSticker
|
||||
|
||||
public inline fun TelegramMediaFile.maskVideoStickerOrThrow(): MaskVideoSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.MaskVideoSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifMaskVideoSticker(block: (MaskVideoSticker) -> T): T? =
|
||||
maskVideoStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiStickerOrNull(): CustomEmojiSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiStickerOrThrow(): CustomEmojiSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.CustomEmojiSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifCustomEmojiSticker(block: (CustomEmojiSticker) -> T): T? =
|
||||
customEmojiStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiSimpleStickerOrNull(): CustomEmojiSimpleSticker? =
|
||||
this as? dev.inmo.tgbotapi.types.files.CustomEmojiSimpleSticker
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiSimpleStickerOrThrow(): CustomEmojiSimpleSticker =
|
||||
this as dev.inmo.tgbotapi.types.files.CustomEmojiSimpleSticker
|
||||
|
||||
public inline fun <T>
|
||||
TelegramMediaFile.ifCustomEmojiSimpleSticker(block: (CustomEmojiSimpleSticker) -> T): T? =
|
||||
customEmojiSimpleStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiAnimatedStickerOrNull(): CustomEmojiAnimatedSticker?
|
||||
= this as? dev.inmo.tgbotapi.types.files.CustomEmojiAnimatedSticker
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiAnimatedStickerOrThrow(): CustomEmojiAnimatedSticker
|
||||
= this as dev.inmo.tgbotapi.types.files.CustomEmojiAnimatedSticker
|
||||
|
||||
public inline fun <T>
|
||||
TelegramMediaFile.ifCustomEmojiAnimatedSticker(block: (CustomEmojiAnimatedSticker) -> T): T? =
|
||||
customEmojiAnimatedStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiVideoStickerOrNull(): CustomEmojiVideoSticker? = this
|
||||
as? dev.inmo.tgbotapi.types.files.CustomEmojiVideoSticker
|
||||
|
||||
public inline fun TelegramMediaFile.customEmojiVideoStickerOrThrow(): CustomEmojiVideoSticker = this
|
||||
as dev.inmo.tgbotapi.types.files.CustomEmojiVideoSticker
|
||||
|
||||
public inline fun <T>
|
||||
TelegramMediaFile.ifCustomEmojiVideoSticker(block: (CustomEmojiVideoSticker) -> T): T? =
|
||||
customEmojiVideoStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.unknownStickerOrNull(): UnknownSticker? = this as?
|
||||
dev.inmo.tgbotapi.types.files.UnknownSticker
|
||||
|
||||
public inline fun TelegramMediaFile.unknownStickerOrThrow(): UnknownSticker = this as
|
||||
dev.inmo.tgbotapi.types.files.UnknownSticker
|
||||
|
||||
public inline fun <T> TelegramMediaFile.ifUnknownSticker(block: (UnknownSticker) -> T): T? =
|
||||
unknownStickerOrNull() ?.let(block)
|
||||
|
||||
public inline fun TelegramMediaFile.thumbedMediaFileOrNull(): ThumbedMediaFile? = this as?
|
||||
dev.inmo.tgbotapi.types.files.ThumbedMediaFile
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.FileUniqueId
|
||||
import dev.inmo.tgbotapi.types.StickerSetName
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
@@ -17,8 +17,10 @@ inline val Sticker.is_video: Boolean
|
||||
inline val Sticker.set_name: StickerSetName?
|
||||
get() = stickerSetName
|
||||
inline val Sticker.mask_position: MaskPosition?
|
||||
get() = maskPosition
|
||||
get() = maskStickerOrNull() ?.maskPosition
|
||||
inline val Sticker.file_size: Long?
|
||||
get() = fileSize
|
||||
inline val Sticker.premium_animation: File?
|
||||
get() = premiumAnimationFile
|
||||
get() = regularStickerOrNull() ?.premiumAnimationFile
|
||||
inline val Sticker.custom_emoji_id: CustomEmojiId?
|
||||
get() = customEmojiStickerOrNull() ?.customEmojiId
|
||||
|
||||
@@ -5,16 +5,23 @@ import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.textsources.link
|
||||
|
||||
|
||||
fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username"
|
||||
fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start="
|
||||
fun makeUsernameStartattachPrefix(username: String) = "$internalLinkBeginning/$username?startattach"
|
||||
fun makeUsernameStartattachLink(username: String, data: String? = null) = "${makeUsernameStartattachPrefix(username)}${data?.let { "=$it" } ?: ""}"
|
||||
inline val Username.link
|
||||
get() = makeUsernameLink(usernameWithoutAt)
|
||||
inline val Username.deepLinkPrefix
|
||||
get() = makeUsernameDeepLinkPrefix(usernameWithoutAt)
|
||||
inline val Username.startattachPrefix
|
||||
get() = makeUsernameStartattachPrefix(usernameWithoutAt)
|
||||
inline fun makeLink(username: Username) = username.link
|
||||
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter"
|
||||
inline fun makeTelegramStartattach(username: String, data: String? = null) = makeUsernameStartattachLink(username, data)
|
||||
inline fun makeDeepLink(username: Username, startParameter: String) = "${username.deepLinkPrefix}$startParameter"
|
||||
inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)
|
||||
inline fun makeTelegramStartattach(username: Username, data: String? = null) = makeTelegramStartattach(username.username, data)
|
||||
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
|
||||
Reference in New Issue
Block a user