diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 27231c67b9..03529ac168 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -220,6 +220,10 @@ const val protectContentField = "protect_content" const val removeCaptionField = "remove_caption" const val replyToMessageIdField = "reply_to_message_id" const val allowSendingWithoutReplyField = "allow_sending_without_reply" +const val quoteField = "quote" +const val quoteParseModeField = "quote_parse_mode" +const val quoteEntitiesField = "quote_entities" +const val quotePositionField = "quote_position" const val replyMarkupField = "reply_markup" const val disableContentTypeDetectionField = "disable_content_type_detection" const val supportStreamingField = "support_streaming" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyParameters.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyParameters.kt new file mode 100644 index 0000000000..fe20f54db0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ReplyParameters.kt @@ -0,0 +1,121 @@ +package dev.inmo.tgbotapi.types + +import dev.inmo.tgbotapi.abstracts.TextedInput +import dev.inmo.tgbotapi.abstracts.TextedWithTextSources +import dev.inmo.tgbotapi.abstracts.WithMessageId +import dev.inmo.tgbotapi.types.message.ParseMode +import dev.inmo.tgbotapi.types.message.RawMessageEntity +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.asTextSources +import dev.inmo.tgbotapi.types.message.textsources.TextSource +import dev.inmo.tgbotapi.types.message.textsources.TextSourcesList +import dev.inmo.tgbotapi.types.message.toRawMessageEntities +import dev.inmo.tgbotapi.utils.extensions.makeSourceString +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ReplyParameters internal constructor( + @SerialName(chatIdField) + val chatIdentifier: ChatIdentifier, + @SerialName(messageIdField) + override val messageId: MessageId, + @SerialName(allowSendingWithoutReplyField) + val allowSendingWithoutReply: Boolean = false, + @SerialName(quoteField) + val quote: String? = null, + @SerialName(quoteParseModeField) + val quoteParseMode: ParseMode? = null, + @SerialName(quoteEntitiesField) + private val quoteEntities: List? = null, + @SerialName(quotePositionField) + val quotePosition: Int? +) : WithMessageId, TextedInput { + override val text: String? + get() = quote + override val textSources: List by lazy { + quoteEntities ?.asTextSources(quote ?: return@lazy emptyList()) ?: emptyList() + } + + constructor( + chatIdentifier: ChatIdentifier, + messageId: MessageId, + entities: TextSourcesList, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + chatIdentifier, + messageId, + allowSendingWithoutReply, + entities.makeSourceString(), + null, + entities.toRawMessageEntities(), + quotePosition + ) + constructor( + metaInfo: Message.MetaInfo, + entities: TextSourcesList, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + metaInfo.chatId, + metaInfo.messageId, + entities, + allowSendingWithoutReply, + quotePosition + ) + constructor( + chatIdentifier: ChatIdentifier, + messageId: MessageId, + quote: String, + quoteParseMode: ParseMode, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + chatIdentifier, + messageId, + allowSendingWithoutReply, + quote, + quoteParseMode, + null, + quotePosition + ) + constructor( + metaInfo: Message.MetaInfo, + quote: String, + quoteParseMode: ParseMode, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + metaInfo.chatId, + metaInfo.messageId, + quote, + quoteParseMode, + allowSendingWithoutReply, + quotePosition + ) + constructor( + chatIdentifier: ChatIdentifier, + messageId: MessageId, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + chatIdentifier, + messageId, + allowSendingWithoutReply, + null, + null, + null, + quotePosition + ) + constructor( + metaInfo: Message.MetaInfo, + allowSendingWithoutReply: Boolean = false, + quotePosition: Int? = null + ) : this( + metaInfo.chatId, + metaInfo.messageId, + allowSendingWithoutReply, + quotePosition + ) +}