1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-09 18:03:47 +00:00

Reused existing code in converters

This commit is contained in:
bpavuk 2024-07-10 18:54:30 +03:00
parent 982b401b28
commit 9fa17c1360
No known key found for this signature in database
GPG Key ID: B501D26D9DEA9CFE

View File

@ -1,27 +1,13 @@
package dev.inmo.tgbotapi.types.message.payments package dev.inmo.tgbotapi.types.message.payments
import dev.inmo.tgbotapi.types.media.TelegramPaidMedia import dev.inmo.tgbotapi.types.media.*
import dev.inmo.tgbotapi.types.media.TelegramPaidMediaPhoto
import dev.inmo.tgbotapi.types.media.TelegramPaidMediaVideo
fun PaidMedia.toTelegramPaidMediaOrNull(): TelegramPaidMedia? = when (this) { fun PaidMedia.toTelegramPaidMediaOrNull(): TelegramPaidMedia? = when (this) {
is PaidMedia.Photo -> TelegramPaidMediaPhoto( is PaidMedia.Photo -> toTelegramMediaPhoto()
file = this.photo.biggest.fileId is PaidMedia.Video -> toTelegramPaidMediaVideo()
)
is PaidMedia.Video -> TelegramPaidMediaPhoto(
file = this.video.fileId
)
is PaidMedia.Preview, is PaidMedia.Unknown -> null is PaidMedia.Preview, is PaidMedia.Unknown -> null
} }
fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = TelegramPaidMediaVideo( fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = this.video.toTelegramPaidMediaVideo()
file = this.video.fileId,
duration = this.video.duration,
width = this.video.width,
height = this.video.height,
thumb = this.video.thumbnail?.fileId
)
fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = TelegramPaidMediaPhoto( fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = this.photo.biggest.toTelegramPaidMediaPhoto()
file = this.photo.fileId
)