mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
SendPoll#closeInfo functionality
This commit is contained in:
parent
976c0b86dc
commit
c6fb50c4a6
@ -12,6 +12,7 @@
|
||||
* `explanationEntitiesField`
|
||||
* `openPeriodField`
|
||||
* `closeDateField`
|
||||
* Field `SendPoll#closeInfo` was added
|
||||
* `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
|
||||
|
@ -71,6 +71,7 @@ fun Poll.createRequest(
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
allowMultipleAnswers,
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
@ -85,6 +86,7 @@ fun Poll.createRequest(
|
||||
isClosed,
|
||||
caption ?.fullListOfSubSource(captionEntities) ?.toMarkdownV2Captions() ?.firstOrNull(),
|
||||
MarkdownV2,
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
@ -96,6 +98,7 @@ fun Poll.createRequest(
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
false,
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
@ -107,6 +110,7 @@ fun Poll.createRequest(
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
false,
|
||||
scheduledCloseInfo,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
@ -119,8 +123,12 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
||||
abstract val options: List<String>
|
||||
abstract val isAnonymous: Boolean
|
||||
abstract val isClosed: Boolean
|
||||
abstract val closeInfo: ScheduledCloseInfo?
|
||||
abstract val type: String
|
||||
|
||||
internal abstract val openPeriod: LongSeconds?
|
||||
internal abstract val closeDate: LongSeconds?
|
||||
|
||||
override fun method(): String = "sendPoll"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
||||
get() = commonResultDeserializer
|
||||
@ -140,6 +148,8 @@ data class SendRegularPoll(
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@ -151,6 +161,14 @@ data class SendRegularPoll(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
|
||||
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?
|
||||
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
}
|
||||
@ -174,6 +192,8 @@ data class SendQuizPoll(
|
||||
override val caption: String? = null,
|
||||
@SerialName(explanationParseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@ -185,6 +205,14 @@ data class SendQuizPoll(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
|
||||
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?
|
||||
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
val correctOptionIdRange = 0 .. options.size
|
||||
|
@ -21,13 +21,22 @@ data class ExactScheduledCloseInfo(
|
||||
) : ScheduledCloseInfo()
|
||||
|
||||
data class ApproximateScheduledCloseInfo(
|
||||
val openDuration: TimeSpan
|
||||
) : ScheduledCloseInfo() {
|
||||
val openDuration: TimeSpan,
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
val startPoint = DateTime.now()
|
||||
val startPoint: DateTime = DateTime.now()
|
||||
) : ScheduledCloseInfo() {
|
||||
override val closeDateTime: DateTime = startPoint + openDuration
|
||||
}
|
||||
|
||||
val LongSeconds.asApproximateScheduledCloseInfo
|
||||
get() = ApproximateScheduledCloseInfo(
|
||||
TimeSpan(this * 1000.0)
|
||||
)
|
||||
val LongSeconds.asExactScheduledCloseInfo
|
||||
get() = ExactScheduledCloseInfo(
|
||||
DateTime(unixMillis = this * 1000.0)
|
||||
)
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
sealed class Poll {
|
||||
abstract val id: PollIdentifier
|
||||
@ -72,15 +81,8 @@ private class RawPoll(
|
||||
val closeDate: LongSeconds? = null
|
||||
) {
|
||||
@Transient
|
||||
val scheduledCloseInfo: ScheduledCloseInfo? = closeDate ?.let {
|
||||
ExactScheduledCloseInfo(
|
||||
DateTime(unixMillis = it * 1000.0)
|
||||
)
|
||||
} ?: openPeriod ?.let {
|
||||
ApproximateScheduledCloseInfo(
|
||||
TimeSpan(it * 1000.0)
|
||||
)
|
||||
}
|
||||
val scheduledCloseInfo: ScheduledCloseInfo?
|
||||
= closeDate ?.asExactScheduledCloseInfo ?: openPeriod ?.asApproximateScheduledCloseInfo
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@ -101,15 +103,11 @@ data class UnknownPollType internal constructor(
|
||||
val raw: JsonObject
|
||||
) : Poll() {
|
||||
@Transient
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = raw.getPrimitiveOrNull(closeDateField) ?.longOrNull ?.let {
|
||||
ExactScheduledCloseInfo(
|
||||
DateTime(unixMillis = it * 1000.0)
|
||||
)
|
||||
} ?: raw.getPrimitiveOrNull(durationField) ?.longOrNull ?.let {
|
||||
ApproximateScheduledCloseInfo(
|
||||
TimeSpan(it * 1000.0)
|
||||
)
|
||||
}
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = raw.getPrimitiveOrNull(
|
||||
closeDateField
|
||||
) ?.longOrNull ?.asExactScheduledCloseInfo ?: raw.getPrimitiveOrNull(
|
||||
openPeriodField
|
||||
) ?.longOrNull ?.asApproximateScheduledCloseInfo
|
||||
}
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
|
Loading…
Reference in New Issue
Block a user