mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
rework of addStickerToSet
This commit is contained in:
parent
afda5e0e7f
commit
1b4d13e452
@ -4,7 +4,7 @@
|
||||
|
||||
**THIS VERSION CONTAINS BREAKING CHANGES**:
|
||||
|
||||
* Fully reworked mechanism of stickers creating
|
||||
* Fully reworked mechanism of stickers creating and adding
|
||||
|
||||
## 6.1.0
|
||||
|
||||
|
@ -2,89 +2,94 @@ 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.InputFile
|
||||
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
|
||||
import dev.inmo.tgbotapi.requests.stickers.AddStaticStickerToSet
|
||||
import dev.inmo.tgbotapi.requests.stickers.AddStickerToSet
|
||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||
import dev.inmo.tgbotapi.types.StickerType
|
||||
import dev.inmo.tgbotapi.types.chat.CommonUser
|
||||
import dev.inmo.tgbotapi.types.UserId
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import dev.inmo.tgbotapi.types.stickers.StickerSet
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
suspend fun TelegramBot.addStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
inputSticker: InputSticker
|
||||
) = execute(
|
||||
AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||
AddStickerToSet(userId, stickerSetName, inputSticker)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = execute(
|
||||
AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
user: CommonUser,
|
||||
stickerSetName: String,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
user: CommonUser,
|
||||
stickerSetName: String,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
user.id, stickerSetName, sticker, emojis, maskPosition
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
suspend fun TelegramBot.addStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSet: StickerSet,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||
sticker: InputFile,
|
||||
emojis: List<String>,
|
||||
keywords: List<String> = emptyList()
|
||||
) = addStickerToSet(
|
||||
userId,
|
||||
stickerSet.name,
|
||||
when (stickerSet.stickerType) {
|
||||
StickerType.CustomEmoji -> InputSticker.WithKeywords.CustomEmoji(
|
||||
sticker,
|
||||
emojis,
|
||||
keywords
|
||||
)
|
||||
StickerType.Mask -> error("Unable to create Mask sticker to the set without maskPosition parameter")
|
||||
StickerType.Regular -> InputSticker.WithKeywords.Regular(
|
||||
sticker,
|
||||
emojis,
|
||||
keywords
|
||||
)
|
||||
is StickerType.Unknown -> error("Unable to create sticker to the set with type ${stickerSet.stickerType}")
|
||||
}
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
suspend fun TelegramBot.addStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSet: StickerSet,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
userId, stickerSet.name, sticker, emojis, maskPosition
|
||||
sticker: InputFile,
|
||||
emojis: List<String>,
|
||||
maskPosition: MaskPosition
|
||||
) = addStickerToSet(
|
||||
userId,
|
||||
stickerSet.name,
|
||||
when (stickerSet.stickerType) {
|
||||
StickerType.CustomEmoji -> InputSticker.WithKeywords.CustomEmoji(
|
||||
sticker,
|
||||
emojis,
|
||||
emptyList()
|
||||
)
|
||||
StickerType.Mask -> InputSticker.Mask(
|
||||
sticker,
|
||||
emojis,
|
||||
maskPosition
|
||||
)
|
||||
StickerType.Regular -> InputSticker.WithKeywords.Regular(
|
||||
sticker,
|
||||
emojis,
|
||||
emptyList()
|
||||
)
|
||||
is StickerType.Unknown -> error("Unable to create sticker to the set with type ${stickerSet.stickerType}")
|
||||
}
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
suspend fun TelegramBot.addStickerToSet(
|
||||
user: CommonUser,
|
||||
stickerSet: StickerSet,
|
||||
sticker: FileId,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||
sticker: InputFile,
|
||||
emojis: List<String>,
|
||||
keywords: List<String> = emptyList()
|
||||
) = addStickerToSet(
|
||||
user.id, stickerSet, sticker, emojis, keywords
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.addStaticStickerToSet(
|
||||
suspend fun TelegramBot.addStickerToSet(
|
||||
user: CommonUser,
|
||||
stickerSet: StickerSet,
|
||||
sticker: MultipartFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
) = addStaticStickerToSet(
|
||||
user.id, stickerSet.name, sticker, emojis, maskPosition
|
||||
sticker: InputFile,
|
||||
emojis: List<String>,
|
||||
maskPosition: MaskPosition
|
||||
) = addStickerToSet(
|
||||
user.id, stickerSet, sticker, emojis, maskPosition
|
||||
)
|
||||
|
@ -1,50 +0,0 @@
|
||||
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.StandardStickerSetAction
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun AddAnimatedStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> {
|
||||
val data = AddAnimatedStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition)
|
||||
return when (sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(tgsStickerField to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class AddAnimatedStickerToSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(emojisField)
|
||||
override val emojis: String,
|
||||
@SerialName(tgsStickerField)
|
||||
val sticker: FileId? = null,
|
||||
@SerialName(maskPositionField)
|
||||
override val maskPosition: MaskPosition? = null
|
||||
) : StandardStickerSetAction {
|
||||
init {
|
||||
if(emojis.isEmpty()) {
|
||||
throw IllegalArgumentException("Emojis must not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "addStickerToSet"
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
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.StandardStickerSetAction
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun AddStaticStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
): Request<Boolean> {
|
||||
val data = AddStaticStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition)
|
||||
return when (sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(pngStickerField to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class AddStaticStickerToSet internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(emojisField)
|
||||
override val emojis: String,
|
||||
@SerialName(pngStickerField)
|
||||
val sticker: FileId? = null,
|
||||
@SerialName(maskPositionField)
|
||||
override val maskPosition: MaskPosition? = null
|
||||
) : StandardStickerSetAction {
|
||||
init {
|
||||
if(emojis.isEmpty()) {
|
||||
throw IllegalArgumentException("Emojis must not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "addStickerToSet"
|
||||
}
|
@ -4,45 +4,32 @@ import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
|
||||
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
import kotlinx.serialization.*
|
||||
|
||||
fun AddVideoStickerToSet(
|
||||
fun AddStickerToSet(
|
||||
userId: UserId,
|
||||
stickerSetName: String,
|
||||
sticker: InputFile,
|
||||
emojis: String,
|
||||
maskPosition: MaskPosition? = null
|
||||
inputSticker: InputSticker
|
||||
): Request<Boolean> {
|
||||
val data = AddVideoStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition)
|
||||
return when (sticker) {
|
||||
val data = AddStickerToSetData(userId, stickerSetName, inputSticker)
|
||||
return when (val sticker = inputSticker.sticker) {
|
||||
is MultipartFile -> CommonMultipartFileRequest(
|
||||
data,
|
||||
mapOf(webmStickerField to sticker)
|
||||
mapOf(sticker.fileId to sticker)
|
||||
)
|
||||
is FileId -> data
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class AddVideoStickerToSet internal constructor(
|
||||
data class AddStickerToSetData internal constructor(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(nameField)
|
||||
override val name: String,
|
||||
@SerialName(emojisField)
|
||||
override val emojis: String,
|
||||
@SerialName(webmStickerField)
|
||||
val sticker: FileId? = null,
|
||||
@SerialName(maskPositionField)
|
||||
override val maskPosition: MaskPosition? = null
|
||||
@SerialName(stickerField)
|
||||
override val inputSticker: InputSticker
|
||||
) : StandardStickerSetAction {
|
||||
init {
|
||||
if(emojis.isEmpty()) {
|
||||
throw IllegalArgumentException("Emojis must not be empty")
|
||||
}
|
||||
}
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.requests.stickers.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||
import dev.inmo.tgbotapi.types.stickers.MaskPosition
|
||||
|
||||
interface StandardStickerSetAction : OwnerStickerSetAction {
|
||||
val emojis: String // must be more than one
|
||||
val maskPosition: MaskPosition?
|
||||
val inputSticker: InputSticker
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user