add setStickerSetThumb

This commit is contained in:
InsanusMokrassar 2020-03-30 22:29:34 +06:00
parent 033ec8f2da
commit 9cd2a6220c
9 changed files with 130 additions and 6 deletions

View File

@ -16,6 +16,7 @@
* `StickerSet#thumb` was added
* `AddStickerToSet` renamed to `AddStaticStickerToSet`
* `AddAnimatedStickerToSet` request was added
* `SetStickerSetThumb` request was added
* `TelegramBotAPI-extensions-api`:
* Extensions `sendDice` was added
* Extension `getMyCommands` request was added
@ -25,6 +26,7 @@
* Extensions `createNewAnimatedStickerSet` was added
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
* Extensions `addAnimatedStickerToSet` was added
* Extensions `setStickerSetThumb` was added
## 0.25.0

View File

@ -0,0 +1,74 @@
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.SetStickerSetThumb
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
suspend fun RequestsExecutor.setStickerSetThumb(
userId: UserId,
stickerSetName: String,
sticker: FileId
) = execute(
SetStickerSetThumb(userId, stickerSetName, sticker)
)
suspend fun RequestsExecutor.setStickerSetThumb(
userId: UserId,
stickerSetName: String,
sticker: MultipartFile
) = execute(
SetStickerSetThumb(userId, stickerSetName, sticker)
)
suspend fun RequestsExecutor.setStickerSetThumb(
user: CommonUser,
stickerSetName: String,
sticker: FileId
) = setStickerSetThumb(
user.id, stickerSetName, sticker
)
suspend fun RequestsExecutor.setStickerSetThumb(
user: CommonUser,
stickerSetName: String,
sticker: MultipartFile
) = setStickerSetThumb(
user.id, stickerSetName, sticker
)
suspend fun RequestsExecutor.setStickerSetThumb(
userId: UserId,
stickerSet: StickerSet,
sticker: FileId
) = setStickerSetThumb(
userId, stickerSet.name, sticker
)
suspend fun RequestsExecutor.setStickerSetThumb(
userId: UserId,
stickerSet: StickerSet,
sticker: MultipartFile
) = setStickerSetThumb(
userId, stickerSet.name, sticker
)
suspend fun RequestsExecutor.setStickerSetThumb(
user: CommonUser,
stickerSet: StickerSet,
sticker: FileId
) = setStickerSetThumb(
user.id, stickerSet.name, sticker
)
suspend fun RequestsExecutor.setStickerSetThumb(
user: CommonUser,
stickerSet: StickerSet,
sticker: MultipartFile
) = setStickerSetThumb(
user.id, stickerSet.name, sticker
)

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
@ -35,7 +36,7 @@ data class AddAnimatedStickerToSet internal constructor(
val sticker: FileId? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StickerSetAction {
) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")

View File

@ -2,10 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
import kotlinx.serialization.*
fun AddStaticStickerToSet(
userId: UserId,
stickerSetName: String,
@ -53,7 +55,7 @@ data class AddStaticStickerToSet internal constructor(
val sticker: FileId? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StickerSetAction {
) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
@ -39,7 +40,7 @@ data class CreateNewAnimatedStickerSet internal constructor(
val containsMasks: Boolean? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StickerSetAction {
) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")

View File

@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
@ -54,7 +55,7 @@ data class CreateNewStaticStickerSet internal constructor(
val containsMasks: Boolean? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StickerSetAction {
) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")

View File

@ -0,0 +1,37 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.*
fun SetStickerSetThumb(
userId: UserId,
stickerSetName: String,
sticker: InputFile
): Request<Boolean> {
val data = SetStickerSetThumb(userId, stickerSetName, sticker as? FileId)
return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest(
data,
mapOf(thumbField to sticker)
)
is FileId -> data
}
}
@Serializable
data class SetStickerSetThumb internal constructor(
@SerialName(userIdField)
override val userId: UserId,
@SerialName(nameField)
override val name: StickerSetName,
@SerialName(thumbField)
val thumb: FileId? = null
) : StickerSetAction {
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "setStickerSetThumb"
}

View File

@ -0,0 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
interface StandardStickerSetAction : StickerSetAction {
val emojis: String // must be more than one
val maskPosition: MaskPosition?
}

View File

@ -9,8 +9,6 @@ import kotlinx.serialization.builtins.serializer
interface StickerSetAction : SimpleRequest<Boolean> {
val userId: UserId
val name: String
val emojis: String // must be more than one
val maskPosition: MaskPosition?
override val resultDeserializer: KSerializer<Boolean>
get() = Boolean.serializer()