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