mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-16 13:49:26 +00:00
support of has_media_spoiler in message and sendPhoto/sendVideo/sendAnimation
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package dev.inmo.tgbotapi.requests.send.abstracts
|
||||
|
||||
interface OptionallyWithSpoilerRequest {
|
||||
val spoilered: Boolean
|
||||
}
|
@@ -25,6 +25,7 @@ fun SendAnimation(
|
||||
thumb: InputFile? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
spoilered: Boolean = false,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
@@ -47,6 +48,7 @@ fun SendAnimation(
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
spoilered,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
@@ -73,6 +75,7 @@ fun SendAnimation(
|
||||
animation: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: TextSourcesList,
|
||||
spoilered: Boolean = false,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
@@ -95,6 +98,7 @@ fun SendAnimation(
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
spoilered,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
@@ -133,6 +137,8 @@ data class SendAnimationData internal constructor(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(hasSpoilerField)
|
||||
override val spoilered: Boolean = false,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(widthField)
|
||||
@@ -157,7 +163,8 @@ data class SendAnimationData internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
ThumbedSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<AnimationContent>>
|
||||
SizedSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
OptionallyWithSpoilerRequest
|
||||
{
|
||||
override val textSources: TextSourcesList? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
|
@@ -23,6 +23,7 @@ fun SendPhoto(
|
||||
photo: InputFile,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
spoilered: Boolean = false,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
@@ -36,6 +37,7 @@ fun SendPhoto(
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
spoilered,
|
||||
threadId,
|
||||
disableNotification,
|
||||
protectContent,
|
||||
@@ -55,6 +57,7 @@ fun SendPhoto(
|
||||
chatId: ChatIdentifier,
|
||||
photo: InputFile,
|
||||
entities: TextSourcesList,
|
||||
spoilered: Boolean = false,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
@@ -68,6 +71,7 @@ fun SendPhoto(
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
spoilered,
|
||||
threadId,
|
||||
disableNotification,
|
||||
protectContent,
|
||||
@@ -98,6 +102,8 @@ data class SendPhotoData internal constructor(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(hasSpoilerField)
|
||||
override val spoilered: Boolean = false,
|
||||
@SerialName(messageThreadIdField)
|
||||
override val threadId: MessageThreadId? = chatId.threadId,
|
||||
@SerialName(disableNotificationField)
|
||||
@@ -113,7 +119,8 @@ data class SendPhotoData internal constructor(
|
||||
) : DataRequest<ContentMessage<PhotoContent>>,
|
||||
SendMessageRequest<ContentMessage<PhotoContent>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
|
||||
TextableSendMessageRequest<ContentMessage<PhotoContent>>
|
||||
TextableSendMessageRequest<ContentMessage<PhotoContent>>,
|
||||
OptionallyWithSpoilerRequest
|
||||
{
|
||||
override val textSources: TextSourcesList? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
|
@@ -25,6 +25,7 @@ fun SendVideo(
|
||||
thumb: InputFile? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
spoilered: Boolean = false,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
@@ -48,6 +49,7 @@ fun SendVideo(
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
spoilered,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
@@ -75,6 +77,7 @@ fun SendVideo(
|
||||
video: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
entities: TextSourcesList,
|
||||
spoilered: Boolean = false,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
height: Int? = null,
|
||||
@@ -98,6 +101,7 @@ fun SendVideo(
|
||||
entities.makeString(),
|
||||
null,
|
||||
entities.toRawMessageEntities(),
|
||||
spoilered,
|
||||
duration,
|
||||
width,
|
||||
height,
|
||||
@@ -137,6 +141,8 @@ data class SendVideoData internal constructor(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(hasSpoilerField)
|
||||
override val spoilered: Boolean = false,
|
||||
@SerialName(durationField)
|
||||
override val duration: Long? = null,
|
||||
@SerialName(widthField)
|
||||
@@ -163,7 +169,8 @@ data class SendVideoData internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
ThumbedSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
DuratedSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<VideoContent>>
|
||||
SizedSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
OptionallyWithSpoilerRequest
|
||||
{
|
||||
override val textSources: TextSourcesList? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
|
@@ -228,6 +228,7 @@ const val allowsMultipleAnswersField = "allows_multiple_answers"
|
||||
const val isAnonymousField = "is_anonymous"
|
||||
const val canManageTopicsField = "can_manage_topics"
|
||||
const val captionEntitiesField = "caption_entities"
|
||||
const val hasSpoilerField = "has_spoiler"
|
||||
const val loginUrlField = "login_url"
|
||||
const val forwardTextField = "forward_text"
|
||||
const val botUsernameField = "bot_username"
|
||||
|
@@ -58,6 +58,7 @@ internal data class RawMessage(
|
||||
private val entities: RawMessageEntities? = null,
|
||||
private val caption: String? = null,
|
||||
private val caption_entities: RawMessageEntities? = null,
|
||||
private val has_media_spoiler: Boolean? = null,
|
||||
private val audio: AudioFile? = null,
|
||||
private val document: DocumentFile? = null,
|
||||
private val animation: AnimationFile? = null,
|
||||
@@ -129,13 +130,15 @@ internal data class RawMessage(
|
||||
video != null -> VideoContent(
|
||||
video,
|
||||
caption,
|
||||
adaptedCaptionEntities
|
||||
adaptedCaptionEntities,
|
||||
has_media_spoiler ?: false
|
||||
)
|
||||
animation != null -> AnimationContent(
|
||||
animation,
|
||||
document,
|
||||
caption,
|
||||
adaptedCaptionEntities
|
||||
adaptedCaptionEntities,
|
||||
has_media_spoiler ?: false
|
||||
)
|
||||
document != null -> DocumentContent(
|
||||
document,
|
||||
@@ -150,7 +153,8 @@ internal data class RawMessage(
|
||||
photo != null -> PhotoContent(
|
||||
photo.toList(),
|
||||
caption,
|
||||
adaptedCaptionEntities
|
||||
adaptedCaptionEntities,
|
||||
has_media_spoiler ?: false
|
||||
)
|
||||
sticker != null -> StickerContent(sticker)
|
||||
dice != null -> DiceContent(dice)
|
||||
|
@@ -23,6 +23,7 @@ sealed interface MessageContent: ResendableContent {
|
||||
mediaGroupPartContentAdditionalBuilder: PolymorphicModuleBuilder<MediaGroupPartContent>.() -> Unit = {},
|
||||
textedMediaContentAdditionalBuilder: PolymorphicModuleBuilder<TextedMediaContent>.() -> Unit = {},
|
||||
mediaContentAdditionalBuilder: PolymorphicModuleBuilder<MediaContent>.() -> Unit = {},
|
||||
spoilerableMediaContentAdditionalBuilder: PolymorphicModuleBuilder<SpoilerableMediaContent>.() -> Unit = {},
|
||||
mediaCollectionContentAdditionalBuilder: PolymorphicModuleBuilder<MediaCollectionContent<*>>.() -> Unit = {},
|
||||
additionalBuilder: PolymorphicModuleBuilder<MessageContent>.() -> Unit = {}
|
||||
) = SerializersModule {
|
||||
@@ -66,6 +67,13 @@ sealed interface MessageContent: ResendableContent {
|
||||
|
||||
mediaContentAdditionalBuilder()
|
||||
}
|
||||
polymorphic(SpoilerableMediaContent::class) {
|
||||
subclass(VideoContent::class)
|
||||
subclass(PhotoContent::class)
|
||||
subclass(AnimationContent::class)
|
||||
|
||||
spoilerableMediaContentAdditionalBuilder()
|
||||
}
|
||||
polymorphic(TextedMediaContent::class) {
|
||||
subclass(PhotoContent::class)
|
||||
subclass(VoiceContent::class)
|
||||
@@ -111,6 +119,10 @@ sealed interface MediaContent: MessageContent {
|
||||
fun asTelegramMedia(): TelegramMedia
|
||||
}
|
||||
|
||||
sealed interface SpoilerableMediaContent : MediaContent {
|
||||
val spoilered: Boolean
|
||||
}
|
||||
|
||||
@ClassCastsIncluded
|
||||
sealed interface ResendableContent {
|
||||
fun createResend(
|
||||
|
@@ -39,6 +39,6 @@ sealed interface MediaGroupPartContent : TextedMediaContent {
|
||||
fun toMediaGroupMemberTelegramMedia(): MediaGroupMemberTelegramMedia
|
||||
}
|
||||
|
||||
sealed interface VisualMediaGroupPartContent : MediaGroupPartContent {
|
||||
sealed interface VisualMediaGroupPartContent : MediaGroupPartContent, SpoilerableMediaContent {
|
||||
override fun toMediaGroupMemberTelegramMedia(): VisualMediaGroupMemberTelegramMedia
|
||||
}
|
||||
|
@@ -18,8 +18,9 @@ data class AnimationContent(
|
||||
override val media: AnimationFile,
|
||||
val includedDocument: DocumentFile?,
|
||||
override val text: String?,
|
||||
override val textSources: TextSourcesList = emptyList()
|
||||
) : TextedMediaContent {
|
||||
override val textSources: TextSourcesList = emptyList(),
|
||||
override val spoilered: Boolean = false
|
||||
) : TextedMediaContent, SpoilerableMediaContent {
|
||||
override fun createResend(
|
||||
chatId: ChatIdentifier,
|
||||
messageThreadId: MessageThreadId?,
|
||||
|
@@ -17,7 +17,8 @@ import kotlinx.serialization.Serializable
|
||||
data class PhotoContent(
|
||||
override val mediaCollection: Photo,
|
||||
override val text: String? = null,
|
||||
override val textSources: TextSourcesList = emptyList()
|
||||
override val textSources: TextSourcesList = emptyList(),
|
||||
override val spoilered: Boolean = false
|
||||
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupPartContent {
|
||||
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
|
||||
|
||||
|
@@ -17,7 +17,8 @@ import kotlinx.serialization.Serializable
|
||||
data class VideoContent(
|
||||
override val media: VideoFile,
|
||||
override val text: String? = null,
|
||||
override val textSources: TextSourcesList = emptyList()
|
||||
override val textSources: TextSourcesList = emptyList(),
|
||||
override val spoilered: Boolean = false
|
||||
) : VisualMediaGroupPartContent {
|
||||
override fun createResend(
|
||||
chatId: ChatIdentifier,
|
||||
|
Reference in New Issue
Block a user