mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
add raw fields for polls
This commit is contained in:
parent
3150cd6a37
commit
41852dde7c
@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.FromUser
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||
import kotlinx.serialization.SerialName
|
||||
@ -20,4 +21,7 @@ data class ChatJoinRequest(
|
||||
val inviteLink: ChatInviteLink,
|
||||
@SerialName(bioField)
|
||||
val bio: String? = null
|
||||
) : FromUser
|
||||
) : FromUser {
|
||||
val dateTime: DateTime
|
||||
get() = date.asDate
|
||||
}
|
||||
|
@ -54,7 +54,9 @@ sealed interface Poll {
|
||||
}
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
sealed interface MultipleAnswersPoll : Poll
|
||||
sealed interface MultipleAnswersPoll : Poll {
|
||||
val allowMultipleAnswers: Boolean
|
||||
}
|
||||
|
||||
@Serializable
|
||||
private class RawPoll(
|
||||
@ -122,7 +124,7 @@ data class RegularPoll(
|
||||
override val votesCount: Int,
|
||||
override val isClosed: Boolean = false,
|
||||
override val isAnonymous: Boolean = false,
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
override val allowMultipleAnswers: Boolean = false,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null
|
||||
) : MultipleAnswersPoll
|
||||
|
||||
|
@ -43,6 +43,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api project(":tgbotapi.core")
|
||||
api "dev.inmo:micro_utils.crypto:$micro_utils_version"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3365,3 +3365,21 @@ inline fun MessageContent.asTextedInput(): TextedInput? = this as? TextedInput
|
||||
|
||||
@PreviewFeature
|
||||
inline fun MessageContent.requireTextedInput(): TextedInput = this as TextedInput
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ScheduledCloseInfo.whenExactScheduledCloseInfo(block: (ExactScheduledCloseInfo) -> T) = asExactScheduledCloseInfo() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ScheduledCloseInfo.asExactScheduledCloseInfo(): ExactScheduledCloseInfo? = this as? ExactScheduledCloseInfo
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ScheduledCloseInfo.requireExactScheduledCloseInfo(): ExactScheduledCloseInfo = this as ExactScheduledCloseInfo
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ScheduledCloseInfo.whenApproximateScheduledCloseInfo(block: (ApproximateScheduledCloseInfo) -> T) = asApproximateScheduledCloseInfo() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ScheduledCloseInfo.asApproximateScheduledCloseInfo(): ApproximateScheduledCloseInfo? = this as? ApproximateScheduledCloseInfo
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ScheduledCloseInfo.requireApproximateScheduledCloseInfo(): ApproximateScheduledCloseInfo = this as ApproximateScheduledCloseInfo
|
||||
|
@ -22,8 +22,6 @@ import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.venue.Venue
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
|
||||
private const val RawFieldsUsageWarning = "This API is raw and experimental. So, it is possible that behaviour of this API will be changed in near updates"
|
||||
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
inline val Message.from: User?
|
||||
get() = asFromUser() ?.from
|
||||
|
@ -0,0 +1,37 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
|
||||
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
|
||||
import dev.inmo.tgbotapi.types.polls.*
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.total_voter_count: Int
|
||||
get() = votesCount
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.type: String
|
||||
get() = when (this) {
|
||||
is RegularPoll -> "regular"
|
||||
is UnknownPollType -> raw["type"]!!.jsonPrimitive.content
|
||||
is QuizPoll -> "quiz"
|
||||
}
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.allows_multiple_answers: Boolean
|
||||
get() = asMultipleAnswersPoll() ?.allowMultipleAnswers == true
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.correct_option_id: Int?
|
||||
get() = asQuizPoll() ?.correctOptionId
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.explanation: String?
|
||||
get() = asQuizPoll() ?.text
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.explanation_entities: TextSourcesList?
|
||||
get() = asQuizPoll() ?.textSources
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.open_period: Seconds?
|
||||
get() = scheduledCloseInfo ?.asApproximateScheduledCloseInfo() ?.openDuration ?.seconds ?.toInt()
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.close_date: TelegramDate?
|
||||
get() = scheduledCloseInfo ?.asExactScheduledCloseInfo() ?.closeDateTime ?.toTelegramDate()
|
@ -0,0 +1,3 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
|
||||
|
||||
internal const val RawFieldsUsageWarning = "This API is raw and experimental. So, it is possible that behaviour of this API will be changed in near updates"
|
Loading…
Reference in New Issue
Block a user