mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
add GetUpdatesConflict
This commit is contained in:
parent
a241c91adf
commit
75cebf5aa3
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user