1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

update for compiling

This commit is contained in:
InsanusMokrassar 2021-02-06 11:53:30 +06:00
parent baf8ed3a77
commit 27dc302f5d
7 changed files with 98 additions and 26 deletions

View File

@ -7,7 +7,7 @@ kotlin.incremental.js=true
kotlin_version=1.4.30 kotlin_version=1.4.30
kotlin_coroutines_version=1.4.2 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 klock_version=2.0.6
uuid_version=0.2.3 uuid_version=0.2.3
ktor_version=1.5.1 ktor_version=1.5.1

View File

@ -17,7 +17,9 @@ class CommonLimiter(
@Transient @Transient
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default) private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
) : RequestLimiter { ) : RequestLimiter {
@Transient
private val quotaSemaphore = Semaphore(lockCount) private val quotaSemaphore = Semaphore(lockCount)
@Transient
private val counterRegeneratorJob = scope.launch { private val counterRegeneratorJob = scope.launch {
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong() val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
while (isActive) { while (isActive) {

View File

@ -18,6 +18,8 @@ data class SetChatPhoto (
override fun method(): String = "setChatPhoto" override fun method(): String = "setChatPhoto"
override val resultDeserializer: DeserializationStrategy<Boolean> override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer() get() = Boolean.serializer()
@Transient
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo) override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
@Transient
override val paramsJson: JsonObject = toJson(serializer()) override val paramsJson: JsonObject = toJson(serializer())
} }

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.requests.send.polls package dev.inmo.tgbotapi.requests.send.polls
import com.soywiz.klock.DateTime import com.soywiz.klock.DateTime
import com.soywiz.klock.TimeSpan
import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.CommonAbstracts.*
import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
@ -16,6 +17,11 @@ import kotlinx.serialization.*
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass() 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( private fun checkPollInfo(
question: String, question: String,
options: List<String> options: List<String>
@ -138,12 +144,23 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
abstract val options: List<String> abstract val options: List<String>
abstract val isAnonymous: Boolean abstract val isAnonymous: Boolean
abstract val isClosed: Boolean abstract val isClosed: Boolean
abstract val closeInfo: ScheduledCloseInfo?
abstract val type: String abstract val type: String
internal abstract val openPeriod: LongSeconds? internal abstract val openPeriod: LongSeconds?
internal abstract val closeDate: 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 fun method(): String = "sendPoll"
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
get() = commonResultDeserializer get() = commonResultDeserializer
@ -163,8 +180,10 @@ data class SendRegularPoll(
override val isClosed: Boolean = false, override val isClosed: Boolean = false,
@SerialName(allowsMultipleAnswersField) @SerialName(allowsMultipleAnswersField)
val allowMultipleAnswers: Boolean = false, val allowMultipleAnswers: Boolean = false,
@Transient @SerialName(openPeriodField)
override val closeInfo: ScheduledCloseInfo? = null, override val openPeriod: LongSeconds?= null,
@SerialName(closeDateField)
override val closeDate: LongSeconds?,
@SerialName(disableNotificationField) @SerialName(disableNotificationField)
override val disableNotification: Boolean = false, override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField) @SerialName(replyToMessageIdField)
@ -178,20 +197,39 @@ data class SendRegularPoll(
override val requestSerializer: SerializationStrategy<*> override val requestSerializer: SerializationStrategy<*>
get() = serializer() 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 { init {
checkPollInfo(question, options) checkPollInfo(question, options)
closeInfo ?.checkSendData() 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( fun SendQuizPoll(
chatId: ChatIdentifier, chatId: ChatIdentifier,
question: String, question: String,
@ -253,6 +291,39 @@ fun SendQuizPoll(
replyMarkup 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 @Serializable
data class SendQuizPoll internal constructor( data class SendQuizPoll internal constructor(
@SerialName(chatIdField) @SerialName(chatIdField)
@ -273,8 +344,10 @@ data class SendQuizPoll internal constructor(
override val parseMode: ParseMode? = null, override val parseMode: ParseMode? = null,
@SerialName(explanationEntitiesField) @SerialName(explanationEntitiesField)
private val rawEntities: List<RawMessageEntity>? = null, private val rawEntities: List<RawMessageEntity>? = null,
@Transient @SerialName(openPeriodField)
override val closeInfo: ScheduledCloseInfo? = null, override val openPeriod: LongSeconds? = null,
@SerialName(closeDateField)
override val closeDate: LongSeconds? = null,
@SerialName(disableNotificationField) @SerialName(disableNotificationField)
override val disableNotification: Boolean = false, override val disableNotification: Boolean = false,
@SerialName(replyToMessageIdField) @SerialName(replyToMessageIdField)
@ -291,14 +364,6 @@ data class SendQuizPoll internal constructor(
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources() 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 { init {
checkPollInfo(question, options) checkPollInfo(question, options)
closeInfo ?.checkSendData() closeInfo ?.checkSendData()

View File

@ -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.DataCredentials
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
import kotlinx.serialization.SerialName import kotlinx.serialization.*
import kotlinx.serialization.Serializable
@Serializable @Serializable
data class AddressSecureValue( data class AddressSecureValue(
@SerialName(dataField) @SerialName(dataField)
override val data: DataCredentials override val data: DataCredentials
) : SecureValueWithData { ) : SecureValueWithData {
@Transient
override val credentials: List<EndDataCredentials> = listOf(data) override val credentials: List<EndDataCredentials> = listOf(data)
} }

View File

@ -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.DataCredentials
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
import kotlinx.serialization.SerialName import kotlinx.serialization.*
import kotlinx.serialization.Serializable
@Serializable @Serializable
data class PersonalDetailsSecureValue( data class PersonalDetailsSecureValue(
@SerialName(dataField) @SerialName(dataField)
override val data: DataCredentials override val data: DataCredentials
) : SecureValueWithData { ) : SecureValueWithData {
@Transient
override val credentials: List<EndDataCredentials> = listOf(data) override val credentials: List<EndDataCredentials> = listOf(data)
} }

View File

@ -33,6 +33,9 @@ val LongSeconds.asApproximateScheduledCloseInfo
get() = ApproximateScheduledCloseInfo( get() = ApproximateScheduledCloseInfo(
TimeSpan(this * 1000.0) TimeSpan(this * 1000.0)
) )
fun LongSeconds.asApproximateScheduledCloseInfo(startPoint: DateTime) = ApproximateScheduledCloseInfo(
TimeSpan(this * 1000.0), startPoint
)
val LongSeconds.asExactScheduledCloseInfo val LongSeconds.asExactScheduledCloseInfo
get() = ExactScheduledCloseInfo( get() = ExactScheduledCloseInfo(
DateTime(unixMillis = this * 1000.0) DateTime(unixMillis = this * 1000.0)