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