1
0
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:
InsanusMokrassar 2023-03-10 14:20:34 +06:00
parent afda5e0e7f
commit 1b4d13e452
6 changed files with 76 additions and 184 deletions

View File

@ -4,7 +4,7 @@
**THIS VERSION CONTAINS BREAKING CHANGES**: **THIS VERSION CONTAINS BREAKING CHANGES**:
* Fully reworked mechanism of stickers creating * Fully reworked mechanism of stickers creating and adding
## 6.1.0 ## 6.1.0

View File

@ -2,89 +2,94 @@ 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.FileId
import dev.inmo.tgbotapi.requests.abstracts.InputFile
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile 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.chat.CommonUser
import dev.inmo.tgbotapi.types.UserId import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.MaskPosition
import dev.inmo.tgbotapi.types.stickers.StickerSet import dev.inmo.tgbotapi.types.stickers.StickerSet
suspend fun TelegramBot.addStaticStickerToSet( suspend fun TelegramBot.addStickerToSet(
userId: UserId, userId: UserId,
stickerSetName: String, stickerSetName: String,
sticker: FileId, inputSticker: InputSticker
emojis: String,
maskPosition: MaskPosition? = null
) = execute( ) = execute(
AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) AddStickerToSet(userId, stickerSetName, inputSticker)
) )
suspend fun TelegramBot.addStaticStickerToSet( suspend fun TelegramBot.addStickerToSet(
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(
userId: UserId, userId: UserId,
stickerSet: StickerSet, stickerSet: StickerSet,
sticker: FileId, sticker: InputFile,
emojis: String, emojis: List<String>,
maskPosition: MaskPosition? = null keywords: List<String> = emptyList()
) = addStaticStickerToSet( ) = addStickerToSet(
userId, stickerSet.name, sticker, emojis, maskPosition 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, userId: UserId,
stickerSet: StickerSet, stickerSet: StickerSet,
sticker: MultipartFile, sticker: InputFile,
emojis: String, emojis: List<String>,
maskPosition: MaskPosition? = null maskPosition: MaskPosition
) = addStaticStickerToSet( ) = addStickerToSet(
userId, stickerSet.name, sticker, emojis, maskPosition 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, user: CommonUser,
stickerSet: StickerSet, stickerSet: StickerSet,
sticker: FileId, sticker: InputFile,
emojis: String, emojis: List<String>,
maskPosition: MaskPosition? = null keywords: List<String> = emptyList()
) = addStaticStickerToSet( ) = addStickerToSet(
user.id, stickerSet.name, sticker, emojis, maskPosition user.id, stickerSet, sticker, emojis, keywords
) )
suspend fun TelegramBot.addStaticStickerToSet( suspend fun TelegramBot.addStickerToSet(
user: CommonUser, user: CommonUser,
stickerSet: StickerSet, stickerSet: StickerSet,
sticker: MultipartFile, sticker: InputFile,
emojis: String, emojis: List<String>,
maskPosition: MaskPosition? = null maskPosition: MaskPosition
) = addStaticStickerToSet( ) = addStickerToSet(
user.id, stickerSet.name, sticker, emojis, maskPosition user.id, stickerSet, sticker, emojis, maskPosition
) )

View File

@ -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"
}

View File

@ -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"
}

View File

@ -4,45 +4,32 @@ import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import kotlinx.serialization.* import kotlinx.serialization.*
fun AddVideoStickerToSet( fun AddStickerToSet(
userId: UserId, userId: UserId,
stickerSetName: String, stickerSetName: String,
sticker: InputFile, inputSticker: InputSticker
emojis: String,
maskPosition: MaskPosition? = null
): Request<Boolean> { ): Request<Boolean> {
val data = AddVideoStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) val data = AddStickerToSetData(userId, stickerSetName, inputSticker)
return when (sticker) { return when (val sticker = inputSticker.sticker) {
is MultipartFile -> CommonMultipartFileRequest( is MultipartFile -> CommonMultipartFileRequest(
data, data,
mapOf(webmStickerField to sticker) mapOf(sticker.fileId to sticker)
) )
is FileId -> data is FileId -> data
} }
} }
@Serializable @Serializable
data class AddVideoStickerToSet internal constructor( data class AddStickerToSetData internal constructor(
@SerialName(userIdField) @SerialName(userIdField)
override val userId: UserId, override val userId: UserId,
@SerialName(nameField) @SerialName(nameField)
override val name: String, override val name: String,
@SerialName(emojisField) @SerialName(stickerField)
override val emojis: String, override val inputSticker: InputSticker
@SerialName(webmStickerField)
val sticker: FileId? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StandardStickerSetAction { ) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")
}
}
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
get() = serializer() get() = serializer()

View File

@ -1,8 +1,8 @@
package dev.inmo.tgbotapi.requests.stickers.abstracts package dev.inmo.tgbotapi.requests.stickers.abstracts
import dev.inmo.tgbotapi.requests.stickers.InputSticker
import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.MaskPosition
interface StandardStickerSetAction : OwnerStickerSetAction { interface StandardStickerSetAction : OwnerStickerSetAction {
val emojis: String // must be more than one val inputSticker: InputSticker
val maskPosition: MaskPosition?
} }