add GetUpdatesConflict

This commit is contained in:
InsanusMokrassar 2021-06-30 13:57:20 +06:00
parent a241c91adf
commit 75cebf5aa3
3 changed files with 14 additions and 0 deletions

View File

@ -17,6 +17,7 @@
* Added `Any#whenFromUser`, `Any#asFromUser` and`Any#requireFromUser` extensions
* `MedaGroupUpdate` and its direct extenders `SentMediaGroupUpdate` and `EditMediaGroupUpdate` became
`sealed interface`s
* New built-in `RequestException` implementator `GetUpdatesConflict` has been added
* `Behaviour Builder`:
* ❗️ All triggers (`on*` extensions) have been modified to work in parallel by some marker by default (new parameter
`markerFactory`, in most cases will work async for different chats)

View File

@ -24,6 +24,12 @@ fun newRequestException(
plainAnswer,
message,
cause
),
description.contains("Conflict: terminated by other getUpdates request") -> GetUpdatesConflict(
response,
plainAnswer,
message,
cause
)
else -> null
}
@ -61,3 +67,6 @@ class WrongFileIdentifierException(response: Response, plainAnswer: String, mess
class TooMuchRequestsException(val retryAfter: RetryAfterError, response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)
class GetUpdatesConflict(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
RequestException(response, plainAnswer, message, cause)

View File

@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
import dev.inmo.micro_utils.coroutines.*
import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.bot.exceptions.GetUpdatesConflict
import dev.inmo.tgbotapi.bot.exceptions.RequestException
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
@ -31,6 +32,9 @@ fun TelegramBot.longPollingFlow(
if (e is RequestException) {
delay(1000L)
}
if (e is GetUpdatesConflict && (exceptionsHandler == null || exceptionsHandler == defaultSafelyExceptionHandler)) {
println("Warning!!! Other bot with the same bot token requests updates with getUpdate in parallel")
}
}
) {
val updates = execute(