1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-09-03 23:29:33 +00:00

#773 fix, improvements in updates handling

This commit is contained in:
2023-06-30 16:35:14 +06:00
parent 81ed820602
commit 2e815a4c37
10 changed files with 130 additions and 30 deletions

View File

@@ -15,7 +15,7 @@ import dev.inmo.tgbotapi.utils.extensions.asMediaGroupMessage
* @see [Update.lastUpdateIdentifier]
*/
fun List<Update>.lastUpdateIdentifier(): UpdateIdentifier? {
return maxByOrNull { it.updateId } ?.updateId
return maxByOrNull { it.updateId } ?.updateId ?.takeIf { it > -1 }
}
/**

View File

@@ -6,6 +6,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.exceptions.*
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.requests.GetUpdates
import dev.inmo.tgbotapi.requests.GetUpdatesRaw
import dev.inmo.tgbotapi.requests.webhook.DeleteWebhook
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
@@ -91,7 +92,9 @@ fun TelegramBot.longPollingFlow(
for (update in updates) {
send(update)
lastUpdateIdentifier = update.updateId
if (update.updateId > -1) {
lastUpdateIdentifier = update.updateId
}
}
}.onFailure {
cancel(it as? CancellationException ?: return@onFailure)