diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f51a07e9d..7773efdffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * `explanationEntitiesField` * `openPeriodField` * `closeDateField` + * `SendQuizPoll` now able to use fields `caption` and `parseMode` for `explanation` functionality + * `quizPollExplanationLimit` was added for checking `QuizPoll` explanation size * Field `TextLinkTextSource#url` was added * Field `TextMentionTextSource#user` was added * Sealed class `ScheduledCloseInfo` was added diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt index 2a084edbe3..372f80a2fb 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/CommonAbstracts/TextSource.kt @@ -16,3 +16,5 @@ data class TextPart( val range: IntRange, val source: TextSource ) + +fun List.justTextSources() = map { it.source } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt index 9db62be4c1..4b83c8a8c3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/polls/SendPoll.kt @@ -1,13 +1,18 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.CaptionedOutput import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownV2 +import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollContent import com.github.insanusmokrassar.TelegramBotAPI.types.polls.* +import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource +import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions import kotlinx.serialization.* private val commonResultDeserializer: DeserializationStrategy> = TelegramBotAPIMessageDeserializationStrategyClass() @@ -78,6 +83,8 @@ fun Poll.createRequest( correctOptionId, isAnonymous, isClosed, + caption ?.fullListOfSubSource(captionEntities) ?.toMarkdownV2Captions() ?.firstOrNull(), + MarkdownV2, disableNotification, replyToMessageId, replyMarkup @@ -163,13 +170,17 @@ data class SendQuizPoll( override val isAnonymous: Boolean = true, @SerialName(isClosedField) override val isClosed: Boolean = false, + @SerialName(explanationField) + override val caption: String? = null, + @SerialName(explanationParseModeField) + override val parseMode: ParseMode? = null, @SerialName(disableNotificationField) override val disableNotification: Boolean = false, @SerialName(replyToMessageIdField) override val replyToMessageId: MessageIdentifier? = null, @SerialName(replyMarkupField) override val replyMarkup: KeyboardMarkup? = null -) : SendPoll() { +) : SendPoll(), CaptionedOutput { override val type: String = quizPollType override val requestSerializer: SerializationStrategy<*> get() = serializer() @@ -181,5 +192,9 @@ data class SendQuizPoll( throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " + "value is $correctOptionId") } + if (caption != null && caption.length !in quizPollExplanationLimit) { + error("Quiz poll explanation size must be in range $quizPollExplanationLimit," + + "but actual explanation contains ${caption.length} symbols") + } } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index cf593a0482..69229daa23 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -55,6 +55,8 @@ val botCommandLimit = botCommandLengthLimit val botCommandDescriptionLimit = 3 .. 256 val botCommandsLimit = 0 .. 100 +val quizPollExplanationLimit = 0 .. 200 + const val chatIdField = "chat_id" const val messageIdField = "message_id" const val updateIdField = "update_id" @@ -253,6 +255,7 @@ const val yShiftField = "y_shift" const val scaleField = "scale" const val explanationEntitiesField = "explanation_entities" +const val explanationParseModeField = "explanation_parse_mode" const val openPeriodField = "open_period" const val closeDateField = "close_date"