mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fixes in startGettingUpdates
This commit is contained in:
parent
ee1f115d77
commit
43ac09a79b
@ -18,6 +18,9 @@
|
|||||||
* `AddAnimatedStickerToSet` request was added
|
* `AddAnimatedStickerToSet` request was added
|
||||||
* `SetStickerSetThumb` request was added
|
* `SetStickerSetThumb` request was added
|
||||||
* Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction`
|
* Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction`
|
||||||
|
* `getUpdatesLimit` was added to be ensure in get updates limit
|
||||||
|
* `GetUpdates` now will check count of requesting updates and throw exception if it is not in range `1 .. 100`
|
||||||
|
* `GetUpdates#limit` now is not nullable and by default set up to 100
|
||||||
* `TelegramBotAPI-extensions-api`:
|
* `TelegramBotAPI-extensions-api`:
|
||||||
* Extensions `sendDice` was added
|
* Extensions `sendDice` was added
|
||||||
* Extension `getMyCommands` request was added
|
* Extension `getMyCommands` request was added
|
||||||
@ -28,6 +31,9 @@
|
|||||||
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
|
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
|
||||||
* Extensions `addAnimatedStickerToSet` was added
|
* Extensions `addAnimatedStickerToSet` was added
|
||||||
* Extensions `setStickerSetThumb` was added
|
* Extensions `setStickerSetThumb` was added
|
||||||
|
* Extension `startGettingUpdates` now will drop `SentMediaGroupUpdate` in case if it is the last in updates group
|
||||||
|
and size of retrieved updates is equal to 100 (max count of retrieved updates)
|
||||||
|
* Extensions `getUpdates` now will receive only not nullable `limit` parameter
|
||||||
|
|
||||||
## 0.25.0
|
## 0.25.0
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
offset: UpdateIdentifier? = null,
|
offset: UpdateIdentifier? = null,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = execute(
|
) = execute(
|
||||||
@ -18,7 +18,7 @@ suspend fun RequestsExecutor.getUpdates(
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
lastUpdate: Update,
|
lastUpdate: Update,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = getUpdates(
|
) = getUpdates(
|
||||||
|
@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestExceptio
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
@ -30,7 +29,20 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
offset = lastUpdateIdentifier?.plus(1),
|
offset = lastUpdateIdentifier?.plus(1),
|
||||||
timeout = timeoutSeconds,
|
timeout = timeoutSeconds,
|
||||||
allowed_updates = allowedUpdates
|
allowed_updates = allowedUpdates
|
||||||
).convertWithMediaGroupUpdates()
|
).let { originalUpdates ->
|
||||||
|
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
||||||
|
/**
|
||||||
|
* Dirty hack for cases when the media group was retrieved not fully:
|
||||||
|
*
|
||||||
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||||
|
* and it will guarantee that it is full
|
||||||
|
*/
|
||||||
|
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
||||||
|
converted - converted.last()
|
||||||
|
} else {
|
||||||
|
converted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
for (update in updates) {
|
for (update in updates) {
|
||||||
|
@ -14,7 +14,7 @@ private val updatesListSerializer = ListSerializer(
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class GetUpdates(
|
data class GetUpdates(
|
||||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||||
val limit: Int? = null,
|
val limit: Int = getUpdatesLimit.last,
|
||||||
val timeout: Seconds? = null,
|
val timeout: Seconds? = null,
|
||||||
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
): SimpleRequest<List<Update>> {
|
): SimpleRequest<List<Update>> {
|
||||||
@ -25,4 +25,10 @@ data class GetUpdates(
|
|||||||
|
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (limit !in getUpdatesLimit) {
|
||||||
|
error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ typealias DiceResult = Int
|
|||||||
|
|
||||||
typealias Seconds = Int
|
typealias Seconds = Int
|
||||||
|
|
||||||
|
val getUpdatesLimit = 1 .. 100
|
||||||
val callbackQueryAnswerLength = 0 until 200
|
val callbackQueryAnswerLength = 0 until 200
|
||||||
val captionLength = 0 until 1024
|
val captionLength = 0 until 1024
|
||||||
val textLength = 0 until 4096
|
val textLength = 0 until 4096
|
||||||
|
Loading…
Reference in New Issue
Block a user