1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +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 package dev.inmo.tgbotapi.extensions.api.stickers
import dev.inmo.tgbotapi.bot.TelegramBot 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.CreateNewStickerSet
import dev.inmo.tgbotapi.requests.stickers.InputSticker import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.StickerFormat import dev.inmo.tgbotapi.types.StickerFormat
import dev.inmo.tgbotapi.types.chat.CommonUser import dev.inmo.tgbotapi.types.chat.CommonUser
import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.stickers.MaskPosition
suspend fun TelegramBot.createNewStickerSet( suspend fun TelegramBot.createNewStickerSet(
userId: UserId, userId: UserId,
@ -16,8 +13,9 @@ suspend fun TelegramBot.createNewStickerSet(
title: String, title: String,
stickersFormat: StickerFormat, stickersFormat: StickerFormat,
stickers: List<InputSticker>, stickers: List<InputSticker>,
needsRepainting: Boolean = false
) = execute( ) = execute(
CreateNewStickerSet(userId, name, title, stickersFormat, stickers) CreateNewStickerSet(userId, name, title, stickersFormat, stickers, needsRepainting)
) )
@ -27,6 +25,7 @@ suspend fun TelegramBot.createNewStickerSet(
title: String, title: String,
stickersFormat: StickerFormat, stickersFormat: StickerFormat,
stickers: List<InputSticker>, stickers: List<InputSticker>,
needsRepainting: Boolean = false,
) = createNewStickerSet( ) = 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 package dev.inmo.tgbotapi.types.files
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.MaskPosition
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
@ -42,6 +43,8 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
get() = false get() = false
val isVideo val isVideo
get() = false get() = false
fun asInputSticker(emojis: List<String> = emoji ?.let { listOf(it) } ?: error("Unable to create input sticker without emojis")): InputSticker
} }
@OptIn(RiskFeature::class) @OptIn(RiskFeature::class)
@ -206,6 +209,12 @@ sealed interface AnimatedSticker : Sticker {
@Serializable @Serializable
sealed interface RegularSticker : Sticker { sealed interface RegularSticker : Sticker {
val premiumAnimationFile: File? val premiumAnimationFile: File?
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.Regular(
fileId,
emojis,
emptyList()
)
} }
@Serializable @Serializable
@ -281,6 +290,12 @@ data class RegularVideoSticker(
@Serializable @Serializable
sealed interface MaskSticker : Sticker { sealed interface MaskSticker : Sticker {
val maskPosition: MaskPosition? val maskPosition: MaskPosition?
override fun asInputSticker(emojis: List<String>) = InputSticker.Mask(
fileId,
emojis,
maskPosition
)
} }
@Serializable @Serializable
data class MaskSimpleSticker( data class MaskSimpleSticker(
@ -354,6 +369,12 @@ data class MaskVideoSticker(
sealed interface CustomEmojiSticker : Sticker { sealed interface CustomEmojiSticker : Sticker {
val customEmojiId: CustomEmojiId val customEmojiId: CustomEmojiId
val needsRepainting: Boolean val needsRepainting: Boolean
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.CustomEmoji(
fileId,
emojis,
emptyList()
)
} }
@Serializable @Serializable
@ -451,4 +472,10 @@ data class UnknownSticker(
@SerialName(stickerFormatField) @SerialName(stickerFormatField)
override val stickerFormat: StickerFormat = StickerFormat.Static, override val stickerFormat: StickerFormat = StickerFormat.Static,
val raw: JsonElement val raw: JsonElement
) : Sticker ) : Sticker {
override fun asInputSticker(emojis: List<String>) = InputSticker.WithKeywords.Regular(
fileId,
emojis,
emptyList()
)
}