1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

add Sticker#asInputSticker

This commit is contained in:
InsanusMokrassar 2023-03-11 17:39:02 +06:00
parent 5992fdd456
commit 810b2ab5a1
2 changed files with 32 additions and 6 deletions

View File

@ -1,14 +1,11 @@
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.CreateNewStickerSet
import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.StickerFormat
import dev.inmo.tgbotapi.types.chat.CommonUser
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.stickers.MaskPosition
suspend fun TelegramBot.createNewStickerSet(
userId: UserId,
@ -16,8 +13,9 @@ suspend fun TelegramBot.createNewStickerSet(
title: String,
stickersFormat: StickerFormat,
stickers: List<InputSticker>,
needsRepainting: Boolean = false
) = execute(
CreateNewStickerSet(userId, name, title, stickersFormat, stickers)
CreateNewStickerSet(userId, name, title, stickersFormat, stickers, needsRepainting)
)
@ -27,6 +25,7 @@ suspend fun TelegramBot.createNewStickerSet(
title: String,
stickersFormat: StickerFormat,
stickers: List<InputSticker>,
needsRepainting: Boolean = false,
) = createNewStickerSet(
user.id, name, title, stickersFormat, stickers
user.id, name, title, stickersFormat, stickers, needsRepainting
)

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.files
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import dev.inmo.tgbotapi.utils.RiskFeature
@ -42,6 +43,8 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
get() = false
val isVideo
get() = false
fun asInputSticker(emojis: List<String> = emoji ?.let { listOf(it) } ?: error("Unable to create input sticker without emojis")): InputSticker
}
@OptIn(RiskFeature::class)
@ -206,6 +209,12 @@ sealed interface AnimatedSticker : Sticker {
@Serializable
sealed interface RegularSticker : Sticker {
val premiumAnimationFile: File?
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.Regular(
fileId,
emojis,
emptyList()
)
}
@Serializable
@ -281,6 +290,12 @@ data class RegularVideoSticker(
@Serializable
sealed interface MaskSticker : Sticker {
val maskPosition: MaskPosition?
override fun asInputSticker(emojis: List<String>) = InputSticker.Mask(
fileId,
emojis,
maskPosition
)
}
@Serializable
data class MaskSimpleSticker(
@ -354,6 +369,12 @@ data class MaskVideoSticker(
sealed interface CustomEmojiSticker : Sticker {
val customEmojiId: CustomEmojiId
val needsRepainting: Boolean
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.CustomEmoji(
fileId,
emojis,
emptyList()
)
}
@Serializable
@ -451,4 +472,10 @@ data class UnknownSticker(
@SerialName(stickerFormatField)
override val stickerFormat: StickerFormat = StickerFormat.Static,
val raw: JsonElement
) : Sticker
) : Sticker {
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.Regular(
fileId,
emojis,
emptyList()
)
}