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

send quiz poll functionality

This commit is contained in:
InsanusMokrassar 2020-04-24 18:46:26 +06:00
parent fee5d8f925
commit 976c0b86dc
4 changed files with 23 additions and 1 deletions

View File

@ -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

View File

@ -16,3 +16,5 @@ data class TextPart(
val range: IntRange,
val source: TextSource
)
fun List<TextPart>.justTextSources() = map { it.source }

View File

@ -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<ContentMessage<PollContent>> = 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")
}
}
}

View File

@ -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"