mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
update for compiling
This commit is contained in:
parent
baf8ed3a77
commit
27dc302f5d
@ -7,7 +7,7 @@ kotlin.incremental.js=true
|
||||
|
||||
kotlin_version=1.4.30
|
||||
kotlin_coroutines_version=1.4.2
|
||||
kotlin_serialisation_runtime_version=1.0.1
|
||||
kotlin_serialisation_runtime_version=1.1.0-RC
|
||||
klock_version=2.0.6
|
||||
uuid_version=0.2.3
|
||||
ktor_version=1.5.1
|
||||
|
@ -17,7 +17,9 @@ class CommonLimiter(
|
||||
@Transient
|
||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : RequestLimiter {
|
||||
@Transient
|
||||
private val quotaSemaphore = Semaphore(lockCount)
|
||||
@Transient
|
||||
private val counterRegeneratorJob = scope.launch {
|
||||
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
|
||||
while (isActive) {
|
||||
|
@ -18,6 +18,8 @@ data class SetChatPhoto (
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
@Transient
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
@Transient
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.polls
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import com.soywiz.klock.TimeSpan
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
||||
@ -16,6 +17,11 @@ import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
|
||||
private inline val ApproximateScheduledCloseInfo.openPeriod
|
||||
get() = openDuration.millisecondsLong.div(1000)
|
||||
private inline val ExactScheduledCloseInfo.closeDate
|
||||
get() = closeDateTime.unixMillisLong.div(1000)
|
||||
|
||||
private fun checkPollInfo(
|
||||
question: String,
|
||||
options: List<String>
|
||||
@ -138,12 +144,23 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
||||
abstract val options: List<String>
|
||||
abstract val isAnonymous: Boolean
|
||||
abstract val isClosed: Boolean
|
||||
abstract val closeInfo: ScheduledCloseInfo?
|
||||
abstract val type: String
|
||||
|
||||
internal abstract val openPeriod: LongSeconds?
|
||||
internal abstract val closeDate: LongSeconds?
|
||||
|
||||
protected val creationDate = DateTime.now()
|
||||
open val closeInfo: ScheduledCloseInfo?
|
||||
get() {
|
||||
val openPeriod = openPeriod
|
||||
val closeDate = closeDate
|
||||
return when {
|
||||
openPeriod != null -> openPeriod.asApproximateScheduledCloseInfo(creationDate)
|
||||
closeDate != null -> closeDate.asExactScheduledCloseInfo
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "sendPoll"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
||||
get() = commonResultDeserializer
|
||||
@ -163,8 +180,10 @@ data class SendRegularPoll(
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?= null,
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@ -178,20 +197,39 @@ data class SendRegularPoll(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
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 {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
}
|
||||
}
|
||||
|
||||
fun SendRegularPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
closeInfo: ScheduledCloseInfo? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendRegularPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
allowMultipleAnswers,
|
||||
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
@ -253,6 +291,39 @@ fun SendQuizPoll(
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
internal fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
correctOptionId: Int,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
explanation: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
rawEntities: List<RawMessageEntity>? = null,
|
||||
closeInfo: ScheduledCloseInfo? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendQuizPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
correctOptionId,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
explanation,
|
||||
parseMode,
|
||||
rawEntities,
|
||||
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SendQuizPoll internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
@ -273,8 +344,10 @@ data class SendQuizPoll internal constructor(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(explanationEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds? = null,
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@ -291,14 +364,6 @@ data class SendQuizPoll internal constructor(
|
||||
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
|
||||
}
|
||||
|
||||
@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 {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
|
@ -4,13 +4,13 @@ import dev.inmo.tgbotapi.types.dataField
|
||||
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AddressSecureValue(
|
||||
@SerialName(dataField)
|
||||
override val data: DataCredentials
|
||||
) : SecureValueWithData {
|
||||
@Transient
|
||||
override val credentials: List<EndDataCredentials> = listOf(data)
|
||||
}
|
@ -4,13 +4,13 @@ import dev.inmo.tgbotapi.types.dataField
|
||||
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class PersonalDetailsSecureValue(
|
||||
@SerialName(dataField)
|
||||
override val data: DataCredentials
|
||||
) : SecureValueWithData {
|
||||
@Transient
|
||||
override val credentials: List<EndDataCredentials> = listOf(data)
|
||||
}
|
@ -33,6 +33,9 @@ val LongSeconds.asApproximateScheduledCloseInfo
|
||||
get() = ApproximateScheduledCloseInfo(
|
||||
TimeSpan(this * 1000.0)
|
||||
)
|
||||
fun LongSeconds.asApproximateScheduledCloseInfo(startPoint: DateTime) = ApproximateScheduledCloseInfo(
|
||||
TimeSpan(this * 1000.0), startPoint
|
||||
)
|
||||
val LongSeconds.asExactScheduledCloseInfo
|
||||
get() = ExactScheduledCloseInfo(
|
||||
DateTime(unixMillis = this * 1000.0)
|
||||
|
Loading…
Reference in New Issue
Block a user