mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2026-04-07 10:32:44 +00:00
reimplementation of PollOption and SendPoll
This commit is contained in:
@@ -49,6 +49,12 @@ fun SendPoll(
|
||||
questionParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -59,14 +65,20 @@ fun SendPoll(
|
||||
replyParameters: ReplyParameters? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendRegularPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
null,
|
||||
questionParseMode,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
false,
|
||||
chatId = chatId,
|
||||
question = question,
|
||||
options = options,
|
||||
closeInfo = null,
|
||||
questionParseMode = questionParseMode,
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = false,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
@@ -84,6 +96,12 @@ fun SendPoll(
|
||||
options: List<InputPollOption>,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -101,6 +119,12 @@ fun SendPoll(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = false,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
@@ -149,7 +173,7 @@ fun Poll.createRequest(
|
||||
replyParameters = replyParameters,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
is QuizPoll -> correctOptionIds ?.let { correctOptionIds ->
|
||||
is QuizPoll -> correctOptionIds?.let { correctOptionIds ->
|
||||
SendQuizPoll(
|
||||
chatId = chatId,
|
||||
questionEntities = textSources,
|
||||
|
||||
@@ -39,12 +39,22 @@ class SendQuizPoll internal constructor(
|
||||
override val isAnonymous: Boolean = true,
|
||||
@SerialName(isClosedField)
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(shuffleOptionsField)
|
||||
val shuffleOptions: Boolean = false,
|
||||
@SerialName(hideResultsUntilClosesField)
|
||||
val hideResultsUntilCloses: Boolean = false,
|
||||
@SerialName(explanationField)
|
||||
val explanation: String? = null,
|
||||
@SerialName(explanationParseModeField)
|
||||
val explanationParseMode: ParseMode? = null,
|
||||
@SerialName(explanationEntitiesField)
|
||||
private val rawExplanationEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(descriptionField)
|
||||
val description: String? = null,
|
||||
@SerialName(descriptionParseModeField)
|
||||
val descriptionParseMode: ParseMode? = null,
|
||||
@SerialName(descriptionEntitiesField)
|
||||
private val rawDescriptionEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds? = null,
|
||||
@SerialName(closeDateField)
|
||||
@@ -80,7 +90,10 @@ class SendQuizPoll internal constructor(
|
||||
override val textSources: List<TextSource>
|
||||
get() = rawQuestionEntities.asTextSources(question)
|
||||
val explanationTextEntities: List<TextSource>? by lazy {
|
||||
rawExplanationEntities ?.asTextSources(text ?: return@lazy null)
|
||||
rawExplanationEntities?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
val descriptionTextSources: List<TextSource>? by lazy {
|
||||
rawDescriptionEntities?.asTextSources(description ?: return@lazy null)
|
||||
}
|
||||
|
||||
constructor(
|
||||
@@ -93,6 +106,10 @@ class SendQuizPoll internal constructor(
|
||||
explanationParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
@@ -114,9 +131,14 @@ class SendQuizPoll internal constructor(
|
||||
rawQuestionEntities = emptyList(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
explanation = explanation,
|
||||
explanationParseMode = explanationParseMode,
|
||||
rawExplanationEntities = emptyList(),
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
rawDescriptionEntities = null,
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -140,6 +162,10 @@ class SendQuizPoll internal constructor(
|
||||
explanationParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
@@ -161,9 +187,14 @@ class SendQuizPoll internal constructor(
|
||||
rawQuestionEntities = questionEntities.toRawMessageEntities(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
explanation = explanation,
|
||||
explanationParseMode = explanationParseMode,
|
||||
rawExplanationEntities = emptyList(),
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
rawDescriptionEntities = null,
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -187,6 +218,9 @@ class SendQuizPoll internal constructor(
|
||||
explanationTextSources: List<TextSource>? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
@@ -208,9 +242,14 @@ class SendQuizPoll internal constructor(
|
||||
rawQuestionEntities = emptyList(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
explanation = explanationTextSources ?.makeSourceString(),
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
explanation = explanationTextSources?.makeSourceString(),
|
||||
explanationParseMode = null,
|
||||
rawExplanationEntities = explanationTextSources ?.toRawMessageEntities(),
|
||||
rawExplanationEntities = explanationTextSources?.toRawMessageEntities(),
|
||||
description = descriptionTextSources?.makeSourceString(),
|
||||
descriptionParseMode = null,
|
||||
rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(),
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -233,6 +272,9 @@ class SendQuizPoll internal constructor(
|
||||
explanationTextSources: List<TextSource>? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
@@ -254,9 +296,14 @@ class SendQuizPoll internal constructor(
|
||||
rawQuestionEntities = questionEntities.toRawMessageEntities(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
explanation = explanationTextSources ?.makeSourceString(),
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
explanation = explanationTextSources?.makeSourceString(),
|
||||
explanationParseMode = null,
|
||||
rawExplanationEntities = explanationTextSources ?.toRawMessageEntities(),
|
||||
rawExplanationEntities = explanationTextSources?.toRawMessageEntities(),
|
||||
description = descriptionTextSources?.makeSourceString(),
|
||||
descriptionParseMode = null,
|
||||
rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(),
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -273,7 +320,7 @@ class SendQuizPoll internal constructor(
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
closeInfo?.checkSendData()
|
||||
val correctOptionIdsRange = 0 until options.size
|
||||
correctOptionIds?.forEach { id ->
|
||||
if (id !in correctOptionIdsRange) {
|
||||
@@ -299,6 +346,10 @@ fun SendQuizPoll(
|
||||
explanationParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -319,6 +370,10 @@ fun SendQuizPoll(
|
||||
explanationParseMode = explanationParseMode,
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
@@ -343,6 +398,10 @@ fun SendQuizPoll(
|
||||
explanationParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -362,6 +421,10 @@ fun SendQuizPoll(
|
||||
explanationParseMode = explanationParseMode,
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
@@ -386,6 +449,9 @@ fun SendQuizPoll(
|
||||
explanationTextSources: List<TextSource>? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -405,6 +471,9 @@ fun SendQuizPoll(
|
||||
explanationTextSources = explanationTextSources,
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
descriptionTextSources = descriptionTextSources,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
@@ -428,6 +497,9 @@ fun SendQuizPoll(
|
||||
explanationTextSources: List<TextSource>? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
shuffleOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -446,6 +518,9 @@ fun SendQuizPoll(
|
||||
explanationTextSources = explanationTextSources,
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
shuffleOptions = shuffleOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
descriptionTextSources = descriptionTextSources,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
|
||||
@@ -40,8 +40,22 @@ class SendRegularPoll constructor(
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
@SerialName(allowsRevotingField)
|
||||
val allowsRevoting: Boolean = true,
|
||||
@SerialName(shuffleOptionsField)
|
||||
val shuffleOptions: Boolean = false,
|
||||
@SerialName(allowAddingOptionsField)
|
||||
val allowAddingOptions: Boolean = false,
|
||||
@SerialName(hideResultsUntilClosesField)
|
||||
val hideResultsUntilCloses: Boolean = false,
|
||||
@SerialName(descriptionField)
|
||||
val description: String? = null,
|
||||
@SerialName(descriptionParseModeField)
|
||||
val descriptionParseMode: ParseMode? = null,
|
||||
@SerialName(descriptionEntitiesField)
|
||||
private val rawDescriptionEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?= null,
|
||||
override val openPeriod: LongSeconds? = null,
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds? = null,
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
@@ -71,6 +85,9 @@ class SendRegularPoll constructor(
|
||||
) : SendPoll() {
|
||||
override val textSources: List<TextSource>
|
||||
get() = rawQuestionEntities.asTextSources(text)
|
||||
val descriptionTextSources: List<TextSource>? by lazy {
|
||||
rawDescriptionEntities?.asTextSources(description ?: return@lazy null)
|
||||
}
|
||||
|
||||
constructor(
|
||||
chatId: ChatIdentifier,
|
||||
@@ -79,7 +96,13 @@ class SendRegularPoll constructor(
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
openPeriod: LongSeconds?= null,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
@@ -100,6 +123,13 @@ class SendRegularPoll constructor(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
rawDescriptionEntities = null,
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -122,7 +152,13 @@ class SendRegularPoll constructor(
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
openPeriod: LongSeconds?= null,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
@@ -143,6 +179,122 @@ class SendRegularPoll constructor(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
rawDescriptionEntities = null,
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
allowPaidBroadcast = allowPaidBroadcast,
|
||||
effectId = effectId,
|
||||
suggestedPostParameters = suggestedPostParameters,
|
||||
replyParameters = replyParameters,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
|
||||
constructor(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<InputPollOption>,
|
||||
questionParseMode: ParseMode? = null,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
allowPaidBroadcast: Boolean = false,
|
||||
effectId: EffectId? = null,
|
||||
suggestedPostParameters: SuggestedPostParameters? = null,
|
||||
replyParameters: ReplyParameters? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) : this(
|
||||
chatId = chatId,
|
||||
question = question,
|
||||
options = options,
|
||||
questionParseMode = questionParseMode,
|
||||
rawQuestionEntities = emptyList(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = descriptionTextSources?.makeSourceString(),
|
||||
descriptionParseMode = null,
|
||||
rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(),
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
allowPaidBroadcast = allowPaidBroadcast,
|
||||
effectId = effectId,
|
||||
suggestedPostParameters = suggestedPostParameters,
|
||||
replyParameters = replyParameters,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
|
||||
constructor(
|
||||
chatId: ChatIdentifier,
|
||||
questionEntities: List<TextSource>,
|
||||
options: List<InputPollOption>,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
descriptionTextSources: List<TextSource>? = null,
|
||||
openPeriod: LongSeconds? = null,
|
||||
closeDate: LongSeconds? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
disableNotification: Boolean = false,
|
||||
protectContent: Boolean = false,
|
||||
allowPaidBroadcast: Boolean = false,
|
||||
effectId: EffectId? = null,
|
||||
suggestedPostParameters: SuggestedPostParameters? = null,
|
||||
replyParameters: ReplyParameters? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) : this(
|
||||
chatId = chatId,
|
||||
question = questionEntities.makeSourceString(),
|
||||
options = options,
|
||||
questionParseMode = null,
|
||||
rawQuestionEntities = questionEntities.toRawMessageEntities(),
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = descriptionTextSources?.makeSourceString(),
|
||||
descriptionParseMode = null,
|
||||
rawDescriptionEntities = descriptionTextSources?.toRawMessageEntities(),
|
||||
openPeriod = openPeriod,
|
||||
closeDate = closeDate,
|
||||
threadId = threadId,
|
||||
@@ -163,7 +315,7 @@ class SendRegularPoll constructor(
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
closeInfo?.checkSendData()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,6 +328,12 @@ fun SendRegularPoll(
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -194,8 +352,14 @@ fun SendRegularPoll(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
@@ -216,6 +380,12 @@ fun SendRegularPoll(
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -233,8 +403,14 @@ fun SendRegularPoll(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
openPeriod = (closeInfo as? ApproximateScheduledCloseInfo)?.openPeriod,
|
||||
closeDate = (closeInfo as? ExactScheduledCloseInfo)?.closeDate,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
@@ -254,6 +430,12 @@ fun SendRegularPoll(
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
allowsRevoting: Boolean = true,
|
||||
shuffleOptions: Boolean = false,
|
||||
allowAddingOptions: Boolean = false,
|
||||
hideResultsUntilCloses: Boolean = false,
|
||||
description: String? = null,
|
||||
descriptionParseMode: ParseMode? = null,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
directMessageThreadId: DirectMessageThreadId? = chatId.directMessageThreadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -273,6 +455,12 @@ fun SendRegularPoll(
|
||||
isAnonymous = isAnonymous,
|
||||
isClosed = isClosed,
|
||||
allowMultipleAnswers = allowMultipleAnswers,
|
||||
allowsRevoting = allowsRevoting,
|
||||
shuffleOptions = shuffleOptions,
|
||||
allowAddingOptions = allowAddingOptions,
|
||||
hideResultsUntilCloses = hideResultsUntilCloses,
|
||||
description = description,
|
||||
descriptionParseMode = descriptionParseMode,
|
||||
threadId = threadId,
|
||||
directMessageThreadId = directMessageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
|
||||
@@ -100,7 +100,7 @@ val mediaCountInMediaGroup: IntRange = 2 .. 10
|
||||
|
||||
val explanationLimit = 0 .. 200
|
||||
|
||||
val openPeriodPollSecondsLimit = 5 .. 600
|
||||
val openPeriodPollSecondsLimit = 5 .. 2628000
|
||||
|
||||
val membersLimit = 1 .. 99999
|
||||
|
||||
@@ -278,11 +278,19 @@ const val lastErrorDateField = "last_error_date"
|
||||
const val lastSynchronizationErrorDateField = "last_synchronization_error_date"
|
||||
const val lastErrorMessageField = "last_error_message"
|
||||
const val votesCountField = "voter_count"
|
||||
const val addedByUserField = "added_by_user"
|
||||
const val addedByChatField = "added_by_chat"
|
||||
const val additionDateField = "addition_date"
|
||||
const val persistentIdField = "persistent_id"
|
||||
const val isClosedField = "is_closed"
|
||||
const val totalVoterCountField = "total_voter_count"
|
||||
const val correctOptionIdField = "correct_option_id"
|
||||
const val correctOptionIdsField = "correct_option_ids"
|
||||
const val allowsMultipleAnswersField = "allows_multiple_answers"
|
||||
const val allowsRevotingField = "allows_revoting"
|
||||
const val shuffleOptionsField = "shuffle_options"
|
||||
const val allowAddingOptionsField = "allow_adding_options"
|
||||
const val hideResultsUntilClosesField = "hide_results_until_closes"
|
||||
const val isAnonymousField = "is_anonymous"
|
||||
const val canManageTopicsField = "can_manage_topics"
|
||||
const val canEditTagField = "can_edit_tag"
|
||||
@@ -598,6 +606,8 @@ const val chatTypeField = "chat_type"
|
||||
|
||||
const val explanationEntitiesField = "explanation_entities"
|
||||
const val explanationParseModeField = "explanation_parse_mode"
|
||||
const val descriptionParseModeField = "description_parse_mode"
|
||||
const val descriptionEntitiesField = "description_entities"
|
||||
const val openPeriodField = "open_period"
|
||||
const val closeDateField = "close_date"
|
||||
const val openingMinuteField = "opening_minute"
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.inmo.tgbotapi.types.polls
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.TextedInput
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.RawMessageEntity
|
||||
import dev.inmo.tgbotapi.types.message.asTextSources
|
||||
import dev.inmo.tgbotapi.types.message.textsources.TextSource
|
||||
import dev.inmo.tgbotapi.types.message.toRawMessageEntities
|
||||
import dev.inmo.tgbotapi.types.textEntitiesField
|
||||
import dev.inmo.tgbotapi.types.textField
|
||||
import dev.inmo.tgbotapi.types.votesCountField
|
||||
import dev.inmo.tgbotapi.utils.EntitiesBuilder
|
||||
import dev.inmo.tgbotapi.utils.EntitiesBuilderBody
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
@@ -17,75 +17,220 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable(PollOptionSerializer::class)
|
||||
sealed class PollOption : TextedInput {
|
||||
abstract val votes: Int
|
||||
@Serializable
|
||||
private data class PollOptionSurrogate(
|
||||
@SerialName(persistentIdField)
|
||||
val id: PollOptionPersistentId,
|
||||
@SerialName(textField)
|
||||
val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
val textEntities: List<RawMessageEntity> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
val votes: Int = 0,
|
||||
@SerialName(addedByUserField)
|
||||
val addedByUser: User? = null,
|
||||
@SerialName(addedByChatField)
|
||||
val addedByChat: Chat? = null,
|
||||
@Serializable(TelegramDateSerializer::class)
|
||||
@SerialName(additionDateField)
|
||||
val additionDate: TelegramDate? = null
|
||||
)
|
||||
|
||||
abstract fun asInput(): InputPollOption
|
||||
@Serializable(PollOption.Companion::class)
|
||||
sealed interface PollOption : TextedInput {
|
||||
val id: PollOptionPersistentId
|
||||
val votes: Int
|
||||
|
||||
fun asInput(): InputPollOption
|
||||
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(PollOption.Companion::class)
|
||||
data class Simple(
|
||||
@SerialName(persistentIdField)
|
||||
override val id: PollOptionPersistentId,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
override val textSources: List<TextSource> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
override val votes: Int = 0
|
||||
) : PollOption {
|
||||
override fun asInput(): InputPollOption = InputPollOption(text, null, textSources)
|
||||
}
|
||||
|
||||
@Serializable(PollOption.LatelyAdded.Companion::class)
|
||||
sealed interface LatelyAdded : PollOption {
|
||||
val additionDate: TelegramDate?
|
||||
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(PollOption.LatelyAdded.Companion::class)
|
||||
data class AddedByUser(
|
||||
@SerialName(persistentIdField)
|
||||
override val id: PollOptionPersistentId,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
override val textSources: List<TextSource> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
override val votes: Int = 0,
|
||||
@SerialName(addedByUserField)
|
||||
val addedByUser: User,
|
||||
@Serializable(TelegramDateSerializer::class)
|
||||
@SerialName(additionDateField)
|
||||
override val additionDate: TelegramDate? = null
|
||||
) : LatelyAdded {
|
||||
override fun asInput(): InputPollOption = InputPollOption(text, null, textSources)
|
||||
}
|
||||
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(PollOption.LatelyAdded.Companion::class)
|
||||
data class AddedByChat(
|
||||
@SerialName(persistentIdField)
|
||||
override val id: PollOptionPersistentId,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
override val textSources: List<TextSource> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
override val votes: Int = 0,
|
||||
@SerialName(addedByChatField)
|
||||
val addedByChat: Chat,
|
||||
@Serializable(TelegramDateSerializer::class)
|
||||
@SerialName(additionDateField)
|
||||
override val additionDate: TelegramDate? = null
|
||||
) : LatelyAdded {
|
||||
override fun asInput(): InputPollOption = InputPollOption(text, null, textSources)
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
companion object : KSerializer<LatelyAdded> {
|
||||
override val descriptor: SerialDescriptor = PollOptionSurrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): LatelyAdded {
|
||||
val surrogate = PollOptionSurrogate.serializer().deserialize(decoder)
|
||||
val textSources = surrogate.textEntities.asTextSources(surrogate.text)
|
||||
return when {
|
||||
surrogate.addedByUser != null -> AddedByUser(
|
||||
surrogate.id, surrogate.text, textSources, surrogate.votes,
|
||||
surrogate.addedByUser, surrogate.additionDate
|
||||
)
|
||||
surrogate.addedByChat != null -> AddedByChat(
|
||||
surrogate.id, surrogate.text, textSources, surrogate.votes,
|
||||
surrogate.addedByChat, surrogate.additionDate
|
||||
)
|
||||
else -> error("LatelyAdded poll option must have either added_by_user or added_by_chat")
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: LatelyAdded) {
|
||||
PollOptionSurrogate.serializer().serialize(
|
||||
encoder,
|
||||
when (value) {
|
||||
is AddedByUser -> PollOptionSurrogate(
|
||||
id = value.id,
|
||||
text = value.text,
|
||||
textEntities = value.textSources.toRawMessageEntities(),
|
||||
votes = value.votes,
|
||||
addedByUser = value.addedByUser,
|
||||
additionDate = value.additionDate
|
||||
)
|
||||
is AddedByChat -> PollOptionSurrogate(
|
||||
id = value.id,
|
||||
text = value.text,
|
||||
textEntities = value.textSources.toRawMessageEntities(),
|
||||
votes = value.votes,
|
||||
addedByChat = value.addedByChat,
|
||||
additionDate = value.additionDate
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
companion object : KSerializer<PollOption> {
|
||||
override val descriptor: SerialDescriptor = PollOptionSurrogate.serializer().descriptor
|
||||
|
||||
companion object {
|
||||
fun simple(
|
||||
id: PollOptionPersistentId,
|
||||
text: String,
|
||||
textSources: List<TextSource>,
|
||||
votes: Int = 0
|
||||
) = SimplePollOption(text, textSources, votes)
|
||||
) = Simple(id, text, textSources, votes)
|
||||
fun simple(
|
||||
id: PollOptionPersistentId,
|
||||
textSources: List<TextSource>,
|
||||
votes: Int = 0
|
||||
) = SimplePollOption(textSources.makeSourceString(), textSources, votes)
|
||||
) = Simple(id, textSources.makeSourceString(), textSources, votes)
|
||||
fun simple(
|
||||
id: PollOptionPersistentId,
|
||||
votes: Int = 0,
|
||||
builder: EntitiesBuilderBody
|
||||
) = simple(
|
||||
id,
|
||||
EntitiesBuilder().apply(builder).build(),
|
||||
votes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
|
||||
@Serializable(PollOptionSerializer::class)
|
||||
data class SimplePollOption (
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
override val textSources: List<TextSource> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
override val votes: Int = 0
|
||||
) : PollOption() {
|
||||
override fun asInput(): InputPollOption = InputPollOption(text, null, textSources)
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object PollOptionSerializer : KSerializer<PollOption> {
|
||||
@Serializable
|
||||
private data class RawPollOption(
|
||||
@SerialName(textField)
|
||||
val text: String,
|
||||
@SerialName(textEntitiesField)
|
||||
val textSources: List<RawMessageEntity> = emptyList(),
|
||||
@SerialName(votesCountField)
|
||||
val votes: Int = 0
|
||||
)
|
||||
override val descriptor: SerialDescriptor = RawPollOption.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): PollOption {
|
||||
val raw = RawPollOption.serializer().deserialize(
|
||||
decoder
|
||||
)
|
||||
|
||||
return SimplePollOption(raw.text, raw.textSources.asTextSources(raw.text), raw.votes)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: PollOption) {
|
||||
when (value) {
|
||||
is SimplePollOption -> RawPollOption.serializer().serialize(
|
||||
encoder,
|
||||
RawPollOption(
|
||||
value.text,
|
||||
value.textSources.toRawMessageEntities(),
|
||||
value.votes
|
||||
override fun deserialize(decoder: Decoder): PollOption {
|
||||
val surrogate = PollOptionSurrogate.serializer().deserialize(decoder)
|
||||
val textSources = surrogate.textEntities.asTextSources(surrogate.text)
|
||||
return when {
|
||||
surrogate.addedByUser != null -> LatelyAdded.AddedByUser(
|
||||
id = surrogate.id,
|
||||
text = surrogate.text,
|
||||
textSources = textSources,
|
||||
votes = surrogate.votes,
|
||||
addedByUser = surrogate.addedByUser,
|
||||
additionDate = surrogate.additionDate
|
||||
)
|
||||
surrogate.addedByChat != null -> LatelyAdded.AddedByChat(
|
||||
id = surrogate.id,
|
||||
text = surrogate.text,
|
||||
textSources = textSources,
|
||||
votes = surrogate.votes,
|
||||
addedByChat = surrogate.addedByChat,
|
||||
additionDate = surrogate.additionDate
|
||||
)
|
||||
else -> Simple(
|
||||
id = surrogate.id,
|
||||
text = surrogate.text,
|
||||
textSources = textSources,
|
||||
votes = surrogate.votes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: PollOption) {
|
||||
PollOptionSurrogate.serializer().serialize(
|
||||
encoder,
|
||||
when (value) {
|
||||
is Simple -> PollOptionSurrogate(
|
||||
id = value.id,
|
||||
text = value.text,
|
||||
textEntities = value.textSources.toRawMessageEntities(),
|
||||
votes = value.votes
|
||||
)
|
||||
is LatelyAdded -> when (value) {
|
||||
is LatelyAdded.AddedByUser -> PollOptionSurrogate(
|
||||
id = value.id,
|
||||
text = value.text,
|
||||
textEntities = value.textSources.toRawMessageEntities(),
|
||||
votes = value.votes,
|
||||
addedByUser = value.addedByUser,
|
||||
additionDate = value.additionDate
|
||||
)
|
||||
is LatelyAdded.AddedByChat -> PollOptionSurrogate(
|
||||
id = value.id,
|
||||
text = value.text,
|
||||
textEntities = value.textSources.toRawMessageEntities(),
|
||||
votes = value.votes,
|
||||
addedByChat = value.addedByChat,
|
||||
additionDate = value.additionDate
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user