mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
fixes in PollContent#createResend, added Poll#createRequest
This commit is contained in:
parent
4e1dbb8741
commit
aece0784ab
@ -11,6 +11,7 @@
|
||||
* `SendQuizPoll` was created and represent `sendPoll` method with type `quiz`
|
||||
* `language` field in PreTextSource now correctly passed from telegram MessageEntities
|
||||
* `PollAnswer` type was added
|
||||
* `Poll#createRequest` extension was added
|
||||
|
||||
## 0.22.0
|
||||
|
||||
|
@ -7,6 +7,7 @@ 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 kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
@ -48,6 +49,47 @@ fun SendPoll(
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
|
||||
fun Poll.createRequest(
|
||||
chatId: ChatIdentifier,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = when (this) {
|
||||
is RegularPoll -> SendRegularPoll(
|
||||
chatId,
|
||||
question,
|
||||
options.map { it.text },
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
allowMultipleAnswers,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
is QuizPoll -> SendQuizPoll(
|
||||
chatId,
|
||||
question,
|
||||
options.map { it.text },
|
||||
correctOptionId,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
is UnknownPollType -> SendRegularPoll(
|
||||
chatId,
|
||||
question,
|
||||
options.map { it.text },
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
false,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
}
|
||||
|
||||
sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
|
||||
abstract val question: String
|
||||
|
@ -2,12 +2,14 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.SendPoll
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.createRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.RegularPoll
|
||||
|
||||
data class PollContent(
|
||||
val poll: Poll
|
||||
@ -17,13 +19,10 @@ data class PollContent(
|
||||
disableNotification: Boolean,
|
||||
replyToMessageId: MessageIdentifier?,
|
||||
replyMarkup: KeyboardMarkup?
|
||||
): Request<ContentMessage<PollContent>> =
|
||||
SendPoll(
|
||||
chatId,
|
||||
poll.question,
|
||||
poll.options.map { it.text },
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
): Request<ContentMessage<PollContent>> = poll.createRequest(
|
||||
chatId,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ sealed class Poll {
|
||||
abstract val question: String
|
||||
abstract val options: List<PollOption>
|
||||
abstract val votesCount: Int
|
||||
abstract val closed: Boolean
|
||||
abstract val isClosed: Boolean
|
||||
abstract val isAnonymous: Boolean
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ data class UnknownPollType(
|
||||
@SerialName(totalVoterCountField)
|
||||
override val votesCount: Int,
|
||||
@SerialName(isClosedField)
|
||||
override val closed: Boolean = false,
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
val raw: String
|
||||
@ -43,7 +43,7 @@ data class RegularPoll(
|
||||
@SerialName(totalVoterCountField)
|
||||
override val votesCount: Int,
|
||||
@SerialName(isClosedField)
|
||||
override val closed: Boolean = false,
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
@ -60,12 +60,12 @@ data class QuizPoll(
|
||||
override val options: List<PollOption>,
|
||||
@SerialName(totalVoterCountField)
|
||||
override val votesCount: Int,
|
||||
@SerialName(isClosedField)
|
||||
override val closed: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(correctOptionIdField)
|
||||
val correctOptionId: Boolean = false
|
||||
val correctOptionId: Int,
|
||||
@SerialName(isClosedField)
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false
|
||||
) : Poll()
|
||||
|
||||
@Serializer(Poll::class)
|
||||
|
Loading…
Reference in New Issue
Block a user