1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-09 09:53: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
import dev.inmo.tgbotapi.types.media.TelegramPaidMedia
import dev.inmo.tgbotapi.types.media.TelegramPaidMediaPhoto
import dev.inmo.tgbotapi.types.media.TelegramPaidMediaVideo
import dev.inmo.tgbotapi.types.media.*
fun PaidMedia.toTelegramPaidMediaOrNull(): TelegramPaidMedia? = when (this) {
is PaidMedia.Photo -> TelegramPaidMediaPhoto(
file = this.photo.biggest.fileId
)
is PaidMedia.Video -> TelegramPaidMediaPhoto(
file = this.video.fileId
)
is PaidMedia.Photo -> toTelegramMediaPhoto()
is PaidMedia.Video -> toTelegramPaidMediaVideo()
is PaidMedia.Preview, is PaidMedia.Unknown -> null
}
fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = TelegramPaidMediaVideo(
file = this.video.fileId,
duration = this.video.duration,
width = this.video.width,
height = this.video.height,
thumb = this.video.thumbnail?.fileId
)
fun PaidMedia.Video.toTelegramPaidMediaVideo(): TelegramPaidMediaVideo = this.video.toTelegramPaidMediaVideo()
fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = TelegramPaidMediaPhoto(
file = this.photo.fileId
)
fun PaidMedia.Photo.toTelegramMediaPhoto(): TelegramPaidMediaPhoto = this.photo.biggest.toTelegramPaidMediaPhoto()