1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

fixes in PollContent#createResend, added Poll#createRequest

This commit is contained in:
InsanusMokrassar 2020-01-23 17:25:25 +06:00
parent 4e1dbb8741
commit aece0784ab
4 changed files with 59 additions and 17 deletions

View File

@ -11,6 +11,7 @@
* `SendQuizPoll` was created and represent `sendPoll` method with type `quiz` * `SendQuizPoll` was created and represent `sendPoll` method with type `quiz`
* `language` field in PreTextSource now correctly passed from telegram MessageEntities * `language` field in PreTextSource now correctly passed from telegram MessageEntities
* `PollAnswer` type was added * `PollAnswer` type was added
* `Poll#createRequest` extension was added
## 0.22.0 ## 0.22.0

View File

@ -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.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 kotlinx.serialization.* import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass() private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
@ -48,6 +49,47 @@ fun SendPoll(
replyMarkup = replyMarkup 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>>, sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> { ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
abstract val question: String abstract val question: String

View File

@ -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.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.polls.SendPoll 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.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
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.content.abstracts.MessageContent 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.Poll
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.RegularPoll
data class PollContent( data class PollContent(
val poll: Poll val poll: Poll
@ -17,11 +19,8 @@ data class PollContent(
disableNotification: Boolean, disableNotification: Boolean,
replyToMessageId: MessageIdentifier?, replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup? replyMarkup: KeyboardMarkup?
): Request<ContentMessage<PollContent>> = ): Request<ContentMessage<PollContent>> = poll.createRequest(
SendPoll(
chatId, chatId,
poll.question,
poll.options.map { it.text },
disableNotification, disableNotification,
replyToMessageId, replyToMessageId,
replyMarkup replyMarkup

View File

@ -11,7 +11,7 @@ sealed class Poll {
abstract val question: String abstract val question: String
abstract val options: List<PollOption> abstract val options: List<PollOption>
abstract val votesCount: Int abstract val votesCount: Int
abstract val closed: Boolean abstract val isClosed: Boolean
abstract val isAnonymous: Boolean abstract val isAnonymous: Boolean
} }
@ -26,7 +26,7 @@ data class UnknownPollType(
@SerialName(totalVoterCountField) @SerialName(totalVoterCountField)
override val votesCount: Int, override val votesCount: Int,
@SerialName(isClosedField) @SerialName(isClosedField)
override val closed: Boolean = false, override val isClosed: Boolean = false,
@SerialName(isAnonymousField) @SerialName(isAnonymousField)
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
val raw: String val raw: String
@ -43,7 +43,7 @@ data class RegularPoll(
@SerialName(totalVoterCountField) @SerialName(totalVoterCountField)
override val votesCount: Int, override val votesCount: Int,
@SerialName(isClosedField) @SerialName(isClosedField)
override val closed: Boolean = false, override val isClosed: Boolean = false,
@SerialName(isAnonymousField) @SerialName(isAnonymousField)
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
@SerialName(allowsMultipleAnswersField) @SerialName(allowsMultipleAnswersField)
@ -60,12 +60,12 @@ data class QuizPoll(
override val options: List<PollOption>, override val options: List<PollOption>,
@SerialName(totalVoterCountField) @SerialName(totalVoterCountField)
override val votesCount: Int, override val votesCount: Int,
@SerialName(isClosedField)
override val closed: Boolean = false,
@SerialName(isAnonymousField)
override val isAnonymous: Boolean = false,
@SerialName(correctOptionIdField) @SerialName(correctOptionIdField)
val correctOptionId: Boolean = false val correctOptionId: Int,
@SerialName(isClosedField)
override val isClosed: Boolean = false,
@SerialName(isAnonymousField)
override val isAnonymous: Boolean = false
) : Poll() ) : Poll()
@Serializer(Poll::class) @Serializer(Poll::class)