mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
send quiz poll functionality
This commit is contained in:
parent
fee5d8f925
commit
976c0b86dc
@ -12,6 +12,8 @@
|
|||||||
* `explanationEntitiesField`
|
* `explanationEntitiesField`
|
||||||
* `openPeriodField`
|
* `openPeriodField`
|
||||||
* `closeDateField`
|
* `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 `TextLinkTextSource#url` was added
|
||||||
* Field `TextMentionTextSource#user` was added
|
* Field `TextMentionTextSource#user` was added
|
||||||
* Sealed class `ScheduledCloseInfo` was added
|
* Sealed class `ScheduledCloseInfo` was added
|
||||||
|
@ -16,3 +16,5 @@ data class TextPart(
|
|||||||
val range: IntRange,
|
val range: IntRange,
|
||||||
val source: TextSource
|
val source: TextSource
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun List<TextPart>.justTextSources() = map { it.source }
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls
|
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.ReplyingMarkupSendMessageRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
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.buttons.KeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
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.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollContent
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollContent
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownV2Captions
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
||||||
@ -78,6 +83,8 @@ fun Poll.createRequest(
|
|||||||
correctOptionId,
|
correctOptionId,
|
||||||
isAnonymous,
|
isAnonymous,
|
||||||
isClosed,
|
isClosed,
|
||||||
|
caption ?.fullListOfSubSource(captionEntities) ?.toMarkdownV2Captions() ?.firstOrNull(),
|
||||||
|
MarkdownV2,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
@ -163,13 +170,17 @@ data class SendQuizPoll(
|
|||||||
override val isAnonymous: Boolean = true,
|
override val isAnonymous: Boolean = true,
|
||||||
@SerialName(isClosedField)
|
@SerialName(isClosedField)
|
||||||
override val isClosed: Boolean = false,
|
override val isClosed: Boolean = false,
|
||||||
|
@SerialName(explanationField)
|
||||||
|
override val caption: String? = null,
|
||||||
|
@SerialName(explanationParseModeField)
|
||||||
|
override val parseMode: ParseMode? = null,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
@SerialName(replyToMessageIdField)
|
@SerialName(replyToMessageIdField)
|
||||||
override val replyToMessageId: MessageIdentifier? = null,
|
override val replyToMessageId: MessageIdentifier? = null,
|
||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: KeyboardMarkup? = null
|
override val replyMarkup: KeyboardMarkup? = null
|
||||||
) : SendPoll() {
|
) : SendPoll(), CaptionedOutput {
|
||||||
override val type: String = quizPollType
|
override val type: String = quizPollType
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
@ -181,5 +192,9 @@ data class SendQuizPoll(
|
|||||||
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
|
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
|
||||||
"value is $correctOptionId")
|
"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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ val botCommandLimit = botCommandLengthLimit
|
|||||||
val botCommandDescriptionLimit = 3 .. 256
|
val botCommandDescriptionLimit = 3 .. 256
|
||||||
val botCommandsLimit = 0 .. 100
|
val botCommandsLimit = 0 .. 100
|
||||||
|
|
||||||
|
val quizPollExplanationLimit = 0 .. 200
|
||||||
|
|
||||||
const val chatIdField = "chat_id"
|
const val chatIdField = "chat_id"
|
||||||
const val messageIdField = "message_id"
|
const val messageIdField = "message_id"
|
||||||
const val updateIdField = "update_id"
|
const val updateIdField = "update_id"
|
||||||
@ -253,6 +255,7 @@ const val yShiftField = "y_shift"
|
|||||||
const val scaleField = "scale"
|
const val scaleField = "scale"
|
||||||
|
|
||||||
const val explanationEntitiesField = "explanation_entities"
|
const val explanationEntitiesField = "explanation_entities"
|
||||||
|
const val explanationParseModeField = "explanation_parse_mode"
|
||||||
const val openPeriodField = "open_period"
|
const val openPeriodField = "open_period"
|
||||||
const val closeDateField = "close_date"
|
const val closeDateField = "close_date"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user