1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

add spoilered in telegrammedia

This commit is contained in:
InsanusMokrassar 2022-12-30 20:28:22 +06:00
parent febd6ce63c
commit 8b5da90e28
11 changed files with 56 additions and 23 deletions

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.abstracts
interface SpoilerableData {
val spoilered: Boolean
}

View File

@ -1,5 +1,5 @@
package dev.inmo.tgbotapi.requests.send.abstracts
interface OptionallyWithSpoilerRequest {
val spoilered: Boolean
}
import dev.inmo.tgbotapi.abstracts.SpoilerableData
interface OptionallyWithSpoilerRequest : SpoilerableData

View File

@ -34,11 +34,13 @@ data class VideoFile(
@Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toTelegramMediaVideo(
text: String? = null,
parseMode: ParseMode? = null
parseMode: ParseMode? = null,
spoilered: Boolean = false
) = TelegramMediaVideo(
fileId,
text,
parseMode,
spoilered,
width,
height,
duration,
@ -47,10 +49,12 @@ inline fun VideoFile.toTelegramMediaVideo(
@Suppress("NOTHING_TO_INLINE")
inline fun VideoFile.toTelegramMediaVideo(
textSources: TextSourcesList
textSources: TextSourcesList,
spoilered: Boolean = false
) = TelegramMediaVideo(
fileId,
textSources,
spoilered,
width,
height,
duration,

View File

@ -20,4 +20,4 @@ sealed interface AudioMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMed
sealed interface DocumentMediaGroupMemberTelegramMedia: MediaGroupMemberTelegramMedia
@Serializable(MediaGroupMemberTelegramMediaSerializer::class)
sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia
sealed interface VisualMediaGroupMemberTelegramMedia : MediaGroupMemberTelegramMedia, SpoilerableTelegramMedia

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.types.media
import dev.inmo.tgbotapi.abstracts.SpoilerableData
sealed interface SpoilerableTelegramMedia : TelegramMedia, SpoilerableData

View File

@ -18,15 +18,17 @@ fun TelegramMediaAnimation(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null,
spoilered: Boolean = false,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = TelegramMediaAnimation(file, text, parseMode, null, width, height, duration, thumb)
) = TelegramMediaAnimation(file, text, parseMode, null, spoilered, width, height, duration, thumb)
fun TelegramMediaAnimation(
file: InputFile,
entities: TextSourcesList,
spoilered: Boolean = false,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
@ -36,6 +38,7 @@ fun TelegramMediaAnimation(
entities.makeString(),
null,
entities.toRawMessageEntities(),
spoilered,
width,
height,
duration,
@ -51,11 +54,13 @@ data class TelegramMediaAnimation internal constructor(
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
override val width: Int? = null,
override val height: Int? = null,
override val duration: Long? = null,
override val thumb: InputFile? = null
) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput {
) : TelegramMedia, SizedTelegramMedia, DuratedTelegramMedia, ThumbedTelegramMedia, TextedOutput, SpoilerableTelegramMedia {
override val type: String = "animation"
override val textSources: TextSourcesList? by lazy {
rawEntities ?.asTextSources(text ?: return@lazy null)

View File

@ -18,13 +18,15 @@ internal const val photoTelegramMediaType = "photo"
fun TelegramMediaPhoto(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null
) = TelegramMediaPhoto(file, text, parseMode, null)
parseMode: ParseMode? = null,
spoilered: Boolean = false
) = TelegramMediaPhoto(file, text, parseMode, null, spoilered)
fun TelegramMediaPhoto(
file: InputFile,
entities: TextSourcesList
) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities())
entities: TextSourcesList,
spoilered: Boolean = false
) = TelegramMediaPhoto(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered)
@Serializable
data class TelegramMediaPhoto internal constructor(
@ -34,7 +36,9 @@ data class TelegramMediaPhoto internal constructor(
@SerialName(parseModeField)
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
) : TelegramMedia, VisualMediaGroupMemberTelegramMedia {
override val type: String = photoTelegramMediaType
override val textSources: TextSourcesList? by lazy {
@ -50,16 +54,20 @@ data class TelegramMediaPhoto internal constructor(
fun PhotoSize.toTelegramMediaPhoto(
text: String? = null,
parseMode: ParseMode? = null
parseMode: ParseMode? = null,
spoilered: Boolean = false
): TelegramMediaPhoto = TelegramMediaPhoto(
fileId,
text,
parseMode
parseMode,
spoilered
)
fun PhotoSize.toTelegramMediaPhoto(
textSources: TextSourcesList = emptyList()
textSources: TextSourcesList = emptyList(),
spoilered: Boolean = false
): TelegramMediaPhoto = TelegramMediaPhoto(
fileId,
textSources
textSources,
spoilered
)

View File

@ -18,20 +18,22 @@ fun TelegramMediaVideo(
file: InputFile,
text: String? = null,
parseMode: ParseMode? = null,
spoilered: Boolean = false,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = TelegramMediaVideo(file, text, parseMode, null, width, height, duration, thumb)
) = TelegramMediaVideo(file, text, parseMode, null, spoilered, width, height, duration, thumb)
fun TelegramMediaVideo(
file: InputFile,
entities: TextSourcesList,
spoilered: Boolean = false,
width: Int? = null,
height: Int? = null,
duration: Long? = null,
thumb: InputFile? = null
) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), width, height, duration, thumb)
) = TelegramMediaVideo(file, entities.makeString(), null, entities.toRawMessageEntities(), spoilered, width, height, duration, thumb)
@Serializable
data class TelegramMediaVideo internal constructor (
@ -42,6 +44,8 @@ data class TelegramMediaVideo internal constructor (
override val parseMode: ParseMode? = null,
@SerialName(captionEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null,
@SerialName(hasSpoilerField)
override val spoilered: Boolean = false,
override val width: Int? = null,
override val height: Int? = null,
override val duration: Long? = null,

View File

@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.abstracts.SpoilerableData
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.types.ChatIdentifier
@ -119,9 +120,7 @@ sealed interface MediaContent: MessageContent {
fun asTelegramMedia(): TelegramMedia
}
sealed interface SpoilerableMediaContent : MediaContent {
val spoilered: Boolean
}
sealed interface SpoilerableMediaContent : MediaContent, SpoilerableData
@ClassCastsIncluded
sealed interface ResendableContent {

View File

@ -34,6 +34,7 @@ data class AnimationContent(
media.fileId,
media.thumb ?.fileId,
textSources,
spoilered,
media.duration,
media.width,
media.height,
@ -48,6 +49,7 @@ data class AnimationContent(
override fun asTelegramMedia(): TelegramMediaAnimation = TelegramMediaAnimation(
media.fileId,
textSources,
spoilered,
media.width,
media.height,
media.duration,

View File

@ -34,6 +34,7 @@ data class PhotoContent(
chatId,
media.fileId,
textSources,
spoilered,
messageThreadId,
disableNotification,
protectContent,
@ -44,5 +45,5 @@ data class PhotoContent(
override fun toMediaGroupMemberTelegramMedia(): TelegramMediaPhoto = asTelegramMedia()
override fun asTelegramMedia(): TelegramMediaPhoto = media.toTelegramMediaPhoto(textSources)
override fun asTelegramMedia(): TelegramMediaPhoto = media.toTelegramMediaPhoto(textSources, spoilered)
}