mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-04-13 13:32:43 +00:00
continue fixing missing parts
This commit is contained in:
@@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.types.message.RawMessageEntity
|
||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.extensions.makeSourceString
|
||||
import dev.inmo.tgbotapi.utils.decodeDataAndJson
|
||||
import korlibs.time.seconds
|
||||
import kotlinx.serialization.*
|
||||
@@ -62,12 +63,10 @@ sealed interface Poll : ReplyInfo.External.ContentVariant, TextedInput {
|
||||
val votesCount: Int
|
||||
val isClosed: Boolean
|
||||
val isAnonymous: Boolean
|
||||
val scheduledCloseInfo: ScheduledCloseInfo?
|
||||
}
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
sealed interface MultipleAnswersPoll : Poll {
|
||||
val allowMultipleAnswers: Boolean
|
||||
val allowsRevoting: Boolean
|
||||
val scheduledCloseInfo: ScheduledCloseInfo?
|
||||
val descriptionTextSources: List<TextSource>
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -90,12 +89,18 @@ private class RawPoll(
|
||||
val type: String,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
@SerialName(correctOptionIdField)
|
||||
@SerialName(correctOptionIdsField)
|
||||
val correctOptionIds: List<Int>? = null,
|
||||
@SerialName(explanationField)
|
||||
val explanation: String? = null,
|
||||
@SerialName(explanationEntitiesField)
|
||||
val explanationEntities: List<RawMessageEntity> = emptyList(),
|
||||
@SerialName(allowsRevotingField)
|
||||
val allowsRevoting: Boolean = true,
|
||||
@SerialName(descriptionField)
|
||||
val description: String? = null,
|
||||
@SerialName(descriptionEntitiesField)
|
||||
val descriptionEntities: List<RawMessageEntity> = emptyList(),
|
||||
@SerialName(openPeriodField)
|
||||
val openPeriod: LongSeconds? = null,
|
||||
@SerialName(closeDateField)
|
||||
@@ -123,6 +128,9 @@ data class UnknownPollType internal constructor(
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
override val allowMultipleAnswers: Boolean = false,
|
||||
override val allowsRevoting: Boolean = true,
|
||||
override val descriptionTextSources: List<TextSource> = emptyList(),
|
||||
@Serializable
|
||||
val raw: JsonElement? = null
|
||||
) : Poll {
|
||||
@@ -145,8 +153,10 @@ data class RegularPoll(
|
||||
override val isClosed: Boolean = false,
|
||||
override val isAnonymous: Boolean = false,
|
||||
override val allowMultipleAnswers: Boolean = false,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null
|
||||
) : MultipleAnswersPoll
|
||||
override val allowsRevoting: Boolean = true,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null,
|
||||
override val descriptionTextSources: List<TextSource> = emptyList()
|
||||
) : Poll
|
||||
|
||||
@Serializable(PollSerializer::class)
|
||||
data class QuizPoll(
|
||||
@@ -160,7 +170,10 @@ data class QuizPoll(
|
||||
val explanationTextSources: List<TextSource> = emptyList(),
|
||||
override val isClosed: Boolean = false,
|
||||
override val isAnonymous: Boolean = false,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null
|
||||
override val allowMultipleAnswers: Boolean = false,
|
||||
override val allowsRevoting: Boolean = true,
|
||||
override val scheduledCloseInfo: ScheduledCloseInfo? = null,
|
||||
override val descriptionTextSources: List<TextSource> = emptyList()
|
||||
) : Poll
|
||||
|
||||
@RiskFeature
|
||||
@@ -173,38 +186,43 @@ object PollSerializer : KSerializer<Poll> {
|
||||
|
||||
return when (rawPoll.type) {
|
||||
quizPollType -> QuizPoll(
|
||||
rawPoll.id,
|
||||
rawPoll.question,
|
||||
rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
rawPoll.options,
|
||||
rawPoll.votesCount,
|
||||
rawPoll.correctOptionIds,
|
||||
rawPoll.explanation,
|
||||
rawPoll.explanation?.let { rawPoll.explanationEntities.asTextSources(it) } ?: emptyList(),
|
||||
rawPoll.isClosed,
|
||||
rawPoll.isAnonymous,
|
||||
rawPoll.scheduledCloseInfo
|
||||
id = rawPoll.id,
|
||||
question = rawPoll.question,
|
||||
textSources = rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
options = rawPoll.options,
|
||||
votesCount = rawPoll.votesCount,
|
||||
correctOptionIds = rawPoll.correctOptionIds,
|
||||
explanation = rawPoll.explanation,
|
||||
explanationTextSources = rawPoll.explanation?.let { rawPoll.explanationEntities.asTextSources(it) } ?: emptyList(),
|
||||
isClosed = rawPoll.isClosed,
|
||||
isAnonymous = rawPoll.isAnonymous,
|
||||
allowMultipleAnswers = rawPoll.allowMultipleAnswers,
|
||||
allowsRevoting = rawPoll.allowsRevoting,
|
||||
scheduledCloseInfo = rawPoll.scheduledCloseInfo,
|
||||
descriptionTextSources = rawPoll.description?.let { rawPoll.descriptionEntities.asTextSources(it) } ?: emptyList()
|
||||
)
|
||||
regularPollType -> RegularPoll(
|
||||
rawPoll.id,
|
||||
rawPoll.question,
|
||||
rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
rawPoll.options,
|
||||
rawPoll.votesCount,
|
||||
rawPoll.isClosed,
|
||||
rawPoll.isAnonymous,
|
||||
rawPoll.allowMultipleAnswers,
|
||||
rawPoll.scheduledCloseInfo
|
||||
id = rawPoll.id,
|
||||
question = rawPoll.question,
|
||||
textSources = rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
options = rawPoll.options,
|
||||
votesCount = rawPoll.votesCount,
|
||||
isClosed = rawPoll.isClosed,
|
||||
isAnonymous = rawPoll.isAnonymous,
|
||||
allowMultipleAnswers = rawPoll.allowMultipleAnswers,
|
||||
allowsRevoting = rawPoll.allowsRevoting,
|
||||
scheduledCloseInfo = rawPoll.scheduledCloseInfo,
|
||||
descriptionTextSources = rawPoll.description?.let { rawPoll.descriptionEntities.asTextSources(it) } ?: emptyList()
|
||||
)
|
||||
else -> UnknownPollType(
|
||||
rawPoll.id,
|
||||
rawPoll.question,
|
||||
rawPoll.options,
|
||||
rawPoll.votesCount,
|
||||
rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
rawPoll.isClosed,
|
||||
rawPoll.isAnonymous,
|
||||
asJson
|
||||
id = rawPoll.id,
|
||||
question = rawPoll.question,
|
||||
options = rawPoll.options,
|
||||
votesCount = rawPoll.votesCount,
|
||||
textSources = rawPoll.questionEntities.asTextSources(rawPoll.question),
|
||||
isClosed = rawPoll.isClosed,
|
||||
isAnonymous = rawPoll.isAnonymous,
|
||||
raw = asJson
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -213,30 +231,37 @@ object PollSerializer : KSerializer<Poll> {
|
||||
val closeInfo = value.scheduledCloseInfo
|
||||
val rawPoll = when (value) {
|
||||
is RegularPoll -> RawPoll(
|
||||
value.id,
|
||||
value.question,
|
||||
value.options,
|
||||
value.votesCount,
|
||||
value.textSources.toRawMessageEntities(),
|
||||
value.isClosed,
|
||||
value.isAnonymous,
|
||||
regularPollType,
|
||||
value.allowMultipleAnswers,
|
||||
id = value.id,
|
||||
question = value.question,
|
||||
options = value.options,
|
||||
votesCount = value.votesCount,
|
||||
questionEntities = value.textSources.toRawMessageEntities(),
|
||||
isClosed = value.isClosed,
|
||||
isAnonymous = value.isAnonymous,
|
||||
type = regularPollType,
|
||||
allowMultipleAnswers = value.allowMultipleAnswers,
|
||||
allowsRevoting = value.allowsRevoting,
|
||||
description = value.descriptionTextSources.makeSourceString().takeIf { it.isNotEmpty() },
|
||||
descriptionEntities = value.descriptionTextSources.toRawMessageEntities(),
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.seconds ?.toLong(),
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000L)
|
||||
)
|
||||
is QuizPoll -> RawPoll(
|
||||
value.id,
|
||||
value.question,
|
||||
value.options,
|
||||
value.votesCount,
|
||||
value.textSources.toRawMessageEntities(),
|
||||
value.isClosed,
|
||||
value.isAnonymous,
|
||||
quizPollType,
|
||||
id = value.id,
|
||||
question = value.question,
|
||||
options = value.options,
|
||||
votesCount = value.votesCount,
|
||||
questionEntities = value.textSources.toRawMessageEntities(),
|
||||
isClosed = value.isClosed,
|
||||
isAnonymous = value.isAnonymous,
|
||||
type = quizPollType,
|
||||
allowMultipleAnswers = value.allowMultipleAnswers,
|
||||
correctOptionIds = value.correctOptionIds,
|
||||
allowsRevoting = value.allowsRevoting,
|
||||
explanation = value.explanation,
|
||||
explanationEntities = value.explanationTextSources.toRawMessageEntities(),
|
||||
description = value.descriptionTextSources.makeSourceString().takeIf { it.isNotEmpty() },
|
||||
descriptionEntities = value.descriptionTextSources.toRawMessageEntities(),
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.seconds ?.toLong(),
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000L)
|
||||
)
|
||||
|
||||
@@ -2617,15 +2617,6 @@ inline fun InlineKeyboardButton.asUnknownInlineKeyboardButton(): UnknownInlineKe
|
||||
inline fun InlineKeyboardButton.requireUnknownInlineKeyboardButton(): UnknownInlineKeyboardButton =
|
||||
this as UnknownInlineKeyboardButton
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> Poll.whenMultipleAnswersPoll(block: (MultipleAnswersPoll) -> T) = asMultipleAnswersPoll()?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun Poll.asMultipleAnswersPoll(): MultipleAnswersPoll? = this as? MultipleAnswersPoll
|
||||
|
||||
@PreviewFeature
|
||||
inline fun Poll.requireMultipleAnswersPoll(): MultipleAnswersPoll = this as MultipleAnswersPoll
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> Poll.whenQuizPoll(block: (QuizPoll) -> T) = asQuizPoll()?.let(block)
|
||||
|
||||
|
||||
@@ -489,7 +489,6 @@ import dev.inmo.tgbotapi.types.payments.stars.StarTransaction
|
||||
import dev.inmo.tgbotapi.types.payments.stars.TransactionPartner
|
||||
import dev.inmo.tgbotapi.types.polls.ApproximateScheduledCloseInfo
|
||||
import dev.inmo.tgbotapi.types.polls.ExactScheduledCloseInfo
|
||||
import dev.inmo.tgbotapi.types.polls.MultipleAnswersPoll
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||
import dev.inmo.tgbotapi.types.polls.PollOptionAdded
|
||||
@@ -2301,12 +2300,6 @@ public inline fun ScheduledCloseInfo.approximateScheduledCloseInfoOrThrow(): App
|
||||
|
||||
public inline fun <T> ScheduledCloseInfo.ifApproximateScheduledCloseInfo(block: (ApproximateScheduledCloseInfo) -> T): T? = approximateScheduledCloseInfoOrNull() ?.let(block)
|
||||
|
||||
public inline fun Poll.multipleAnswersPollOrNull(): MultipleAnswersPoll? = this as? dev.inmo.tgbotapi.types.polls.MultipleAnswersPoll
|
||||
|
||||
public inline fun Poll.multipleAnswersPollOrThrow(): MultipleAnswersPoll = this as dev.inmo.tgbotapi.types.polls.MultipleAnswersPoll
|
||||
|
||||
public inline fun <T> Poll.ifMultipleAnswersPoll(block: (MultipleAnswersPoll) -> T): T? = multipleAnswersPollOrNull() ?.let(block)
|
||||
|
||||
public inline fun Poll.unknownPollTypeOrNull(): UnknownPollType? = this as? dev.inmo.tgbotapi.types.polls.UnknownPollType
|
||||
|
||||
public inline fun Poll.unknownPollTypeOrThrow(): UnknownPollType = this as dev.inmo.tgbotapi.types.polls.UnknownPollType
|
||||
|
||||
@@ -21,7 +21,7 @@ val Poll.type: String
|
||||
}
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.allows_multiple_answers: Boolean
|
||||
get() = asMultipleAnswersPoll() ?.allowMultipleAnswers == true
|
||||
get() = allowMultipleAnswers
|
||||
@RiskFeature(RawFieldsUsageWarning)
|
||||
val Poll.correct_option_id: List<Int>?
|
||||
get() = asQuizPoll() ?.correctOptionIds
|
||||
|
||||
Reference in New Issue
Block a user