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

add TextQuote

This commit is contained in:
InsanusMokrassar 2024-01-07 20:51:29 +06:00
parent 955e9ca871
commit f637b480b1
14 changed files with 100 additions and 32 deletions

View File

@ -665,3 +665,4 @@ const val winnersField = "winners"
const val additionalChatCountField = "additional_chat_count"
const val unclaimedPrizeCountField = "unclaimed_prize_count"
const val wasRefundedField = "was_refunded"
const val isManualField = "is_manual"

View File

@ -0,0 +1,38 @@
package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.types.message.RawMessageEntities
import dev.inmo.tgbotapi.types.message.asTextSources
import dev.inmo.tgbotapi.types.message.textsources.TextSource
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmName
@Serializable
data class TextQuote private constructor(
@SerialName(textField)
override val text: String,
@SerialName(positionField)
val position: Int,
@SerialName(entitiesField)
private val entities: RawMessageEntities? = null,
@SerialName(isManualField)
val isManual: Boolean = false
) : TextedInput {
override val textSources: List<TextSource> by lazy {
entities ?.asTextSources(text) ?: emptyList()
}
companion object {
@JvmName("PublicConstructor")
operator fun invoke(
text: String,
position: Int,
textSources: List<TextSource> = emptyList(),
isManual: Boolean = false
) = TextQuote(
text, position, textSources.toRawMessageEntities(position), isManual
)
}
}

View File

@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.abstracts
import dev.inmo.tgbotapi.types.TextQuote
interface WithOptionalQuoteInfo {
val quote: TextQuote?
}

View File

@ -55,6 +55,7 @@ internal data class RawMessage(
private val is_automatic_forward: Boolean? = null,
private val reply_to_message: RawMessage? = null,
private val external_reply: ReplyInfo.External? = null,
private val quote: TextQuote? = null,
private val via_bot: CommonBot? = null,
private val edit_date: TelegramDate? = null,
private val has_protected_content: Boolean? = null,
@ -148,40 +149,46 @@ internal data class RawMessage(
messageId,
story
)
text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text), link_preview_options)
text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text), link_preview_options, quote)
audio != null -> AudioContent(
audio,
caption,
adaptedCaptionEntities
adaptedCaptionEntities,
quote
)
video != null -> VideoContent(
video,
caption,
adaptedCaptionEntities,
has_media_spoiler ?: false
has_media_spoiler ?: false,
quote
)
animation != null -> AnimationContent(
animation,
document,
caption,
adaptedCaptionEntities,
has_media_spoiler ?: false
has_media_spoiler ?: false,
quote
)
document != null -> DocumentContent(
document,
caption,
adaptedCaptionEntities
adaptedCaptionEntities,
quote
)
voice != null -> VoiceContent(
voice,
caption,
adaptedCaptionEntities
adaptedCaptionEntities,
quote
)
photo != null -> PhotoContent(
photo,
caption,
adaptedCaptionEntities,
has_media_spoiler ?: false
has_media_spoiler ?: false,
quote
)
sticker != null -> StickerContent(sticker)
dice != null -> DiceContent(dice)

View File

@ -1,9 +1,12 @@
package dev.inmo.tgbotapi.types.message
import dev.inmo.micro_utils.serialization.mapper.MapperSerializer
import dev.inmo.tgbotapi.types.CustomEmojiId
import dev.inmo.tgbotapi.types.chat.User
import dev.inmo.tgbotapi.types.message.textsources.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
@Serializable
internal data class RawMessageEntity(

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.files.AudioFile
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.media.*
@ -22,7 +23,7 @@ sealed interface DocumentMediaGroupPartContent : MediaGroupPartContent {
override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia
}
sealed interface TextedMediaContent : TextedContent, MediaContent
sealed interface TextedMediaContent : TextedContent, MediaContent, WithOptionalQuoteInfo
sealed interface MediaGroupCollectionContent<T : MediaGroupPartContent> : TextedMediaContent {
@Serializable

View File

@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.media.TelegramMediaAnimation
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.TextQuote
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.AnimationFile
import dev.inmo.tgbotapi.types.files.DocumentFile
@ -19,7 +20,8 @@ data class AnimationContent(
val includedDocument: DocumentFile?,
override val text: String?,
override val textSources: TextSourcesList = emptyList(),
override val spoilered: Boolean = false
override val spoilered: Boolean = false,
override val quote: TextQuote? = null
) : TextedMediaContent, SpoilerableMediaContent {
override fun createResend(
chatId: ChatIdentifier,

View File

@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.media.toTelegramMediaAudio
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.TextQuote
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.AudioFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
@ -17,7 +18,8 @@ import kotlinx.serialization.Serializable
data class AudioContent(
override val media: AudioFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
override val textSources: TextSourcesList = emptyList(),
override val quote: TextQuote? = null
) : AudioMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,

View File

@ -9,6 +9,8 @@ import dev.inmo.tgbotapi.types.media.toTelegramMediaDocument
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.TextQuote
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.DocumentFile
import dev.inmo.tgbotapi.types.files.asDocumentFile
@ -19,7 +21,8 @@ import kotlinx.serialization.Serializable
data class DocumentContent(
override val media: DocumentFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
override val textSources: TextSourcesList = emptyList(),
override val quote: TextQuote? = null
) : DocumentMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,
@ -52,7 +55,8 @@ inline fun MediaContent.asDocumentContent() = when (this) {
is TextedInput -> DocumentContent(
media.asDocumentFile(),
text,
textSources
textSources,
(this as? WithOptionalQuoteInfo) ?.quote
)
else -> DocumentContent(
media.asDocumentFile()

View File

@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendMediaGroup
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MediaGroupIdentifier
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.TelegramMediaFile
import dev.inmo.tgbotapi.types.media.TelegramMedia
@ -16,10 +14,12 @@ import kotlinx.serialization.Serializable
@Serializable
data class MediaGroupContent<T : MediaGroupPartContent>(
override val group: List<MediaGroupCollectionContent.PartWrapper<T>>,
override val mediaGroupId: MediaGroupIdentifier
) : MediaGroupCollectionContent<T> {
override val mediaGroupId: MediaGroupIdentifier,
) : MediaGroupCollectionContent<T>, WithOptionalQuoteInfo {
val mainContent: MediaGroupPartContent
get() = group.first().content
override val quote: TextQuote?
get() = mainContent.quote
override val media: TelegramMediaFile
get() = mainContent.media

View File

@ -8,6 +8,8 @@ import dev.inmo.tgbotapi.types.media.toTelegramMediaPhoto
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.TextQuote
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
@ -18,8 +20,9 @@ data class PhotoContent(
override val mediaCollection: Photo,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList(),
override val spoilered: Boolean = false
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupPartContent {
override val spoilered: Boolean = false,
override val quote: TextQuote? = null
) : MediaCollectionContent<PhotoSize>, VisualMediaGroupPartContent, WithOptionalQuoteInfo {
override val media: PhotoSize = mediaCollection.biggest() ?: throw IllegalStateException("Can't locate any photo size for this content")
override fun createResend(

View File

@ -3,11 +3,9 @@ package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.abstracts.TextedInput
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.SendTextMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.LinkPreviewOptions
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import kotlinx.serialization.Serializable
@ -16,8 +14,9 @@ import kotlinx.serialization.Serializable
data class TextContent(
override val text: String,
override val textSources: TextSourcesList = emptyList(),
val linkPreviewOptions: LinkPreviewOptions? = null
) : TextedContent {
val linkPreviewOptions: LinkPreviewOptions? = null,
override val quote: TextQuote? = null
) : TextedContent, WithOptionalQuoteInfo {
override fun createResend(
chatId: ChatIdentifier,
messageThreadId: MessageThreadId?,

View File

@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.media.TelegramMediaVideo
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.TextQuote
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.VideoFile
import dev.inmo.tgbotapi.types.files.toTelegramMediaVideo
@ -18,7 +19,8 @@ data class VideoContent(
override val media: VideoFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList(),
override val spoilered: Boolean = false
override val spoilered: Boolean = false,
override val quote: TextQuote? = null
) : VisualMediaGroupPartContent {
override fun createResend(
chatId: ChatIdentifier,

View File

@ -2,22 +2,21 @@ package dev.inmo.tgbotapi.types.message.content
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.requests.send.media.SendVoice
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.media.TelegramMediaAudio
import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageId
import dev.inmo.tgbotapi.types.MessageThreadId
import dev.inmo.tgbotapi.types.abstracts.WithOptionalQuoteInfo
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.VoiceFile
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.threadId
import kotlinx.serialization.Serializable
@Serializable
data class VoiceContent(
override val media: VoiceFile,
override val text: String? = null,
override val textSources: TextSourcesList = emptyList()
override val textSources: TextSourcesList = emptyList(),
override val quote: TextQuote? = null
) : TextedMediaContent {
override fun createResend(
chatId: ChatIdentifier,