mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
optimise Photo#biggest, add MediaGroupContent#toMediaGroupMemberInputMedia
This commit is contained in:
parent
1518731786
commit
09cb429a59
@ -31,3 +31,4 @@
|
|||||||
* `MessageContent` now is `ResendableContent`
|
* `MessageContent` now is `ResendableContent`
|
||||||
* Now all media sending factories which contains `thumb` have default `null` value
|
* Now all media sending factories which contains `thumb` have default `null` value
|
||||||
* `ChatIdentifier` classes now are `data` classes
|
* `ChatIdentifier` classes now are `data` classes
|
||||||
|
* Now `MediaGroupContent` interface contains `toMediaGroupMemberInputMedia` method for easily creating mirror input media
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
package com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia
|
||||||
|
|
||||||
interface DuratedInputMedia : InputMedia {
|
interface DuratedInputMedia : InputMedia {
|
||||||
val duration: Int?
|
val duration: Long?
|
||||||
}
|
}
|
@ -20,7 +20,7 @@ data class InputMediaAnimation(
|
|||||||
@Optional
|
@Optional
|
||||||
override val height: Int? = null,
|
override val height: Int? = null,
|
||||||
@Optional
|
@Optional
|
||||||
override val duration: Int? = null,
|
override val duration: Long? = null,
|
||||||
@Transient
|
@Transient
|
||||||
override val thumb: InputFile? = null
|
override val thumb: InputFile? = null
|
||||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia {
|
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia {
|
||||||
|
@ -16,7 +16,7 @@ data class InputMediaAudio(
|
|||||||
@Optional
|
@Optional
|
||||||
override val parseMode: ParseMode? = null,
|
override val parseMode: ParseMode? = null,
|
||||||
@Optional
|
@Optional
|
||||||
override val duration: Int? = null,
|
override val duration: Long? = null,
|
||||||
@Optional
|
@Optional
|
||||||
val performer: String? = null,
|
val performer: String? = null,
|
||||||
@Optional
|
@Optional
|
||||||
|
@ -20,7 +20,7 @@ data class InputMediaVideo(
|
|||||||
@Optional
|
@Optional
|
||||||
override val height: Int? = null,
|
override val height: Int? = null,
|
||||||
@Optional
|
@Optional
|
||||||
override val duration: Int? = null,
|
override val duration: Long? = null,
|
||||||
@Transient
|
@Transient
|
||||||
override val thumb: InputFile? = null
|
override val thumb: InputFile? = null
|
||||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
|
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, CaptionedInputMedia, MediaGroupMemberInputMedia {
|
||||||
|
@ -7,14 +7,8 @@ import kotlinx.serialization.internal.ArrayListSerializer
|
|||||||
|
|
||||||
typealias Photo = List<PhotoSize>
|
typealias Photo = List<PhotoSize>
|
||||||
|
|
||||||
fun Photo.biggest(): PhotoSize? {
|
fun Photo.biggest(): PhotoSize? = maxBy {
|
||||||
var biggest: PhotoSize = firstOrNull() ?: return null
|
it.resolution
|
||||||
forEach {
|
|
||||||
if (it.resolution > biggest.resolution) {
|
|
||||||
biggest = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return biggest
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
|
object PhotoSerializer : KSerializer<Photo> by ArrayListSerializer(
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts
|
||||||
|
|
||||||
interface MediaGroupContent : MessageContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||||
|
|
||||||
|
interface MediaGroupContent : MessageContent {
|
||||||
|
fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia
|
||||||
|
}
|
@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendPhoto
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaPhoto
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
||||||
@ -32,4 +34,10 @@ data class PhotoContent(
|
|||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaPhoto(
|
||||||
|
media.biggest() ?.fileId ?: throw IllegalStateException("Can't locate any photo size for this content"),
|
||||||
|
toMarkdownCaption(),
|
||||||
|
MarkdownParseMode
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content.media
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.SendVideo
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMediaVideo
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.MediaGroupMemberInputMedia
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownParseMode
|
||||||
@ -36,4 +38,14 @@ data class VideoContent(
|
|||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia = InputMediaVideo(
|
||||||
|
media.fileId,
|
||||||
|
toMarkdownCaption(),
|
||||||
|
MarkdownParseMode,
|
||||||
|
media.width,
|
||||||
|
media.height,
|
||||||
|
media.duration,
|
||||||
|
media.thumb ?.fileId
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user