mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +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
|
* Added `Any#whenFromUser`, `Any#asFromUser` and`Any#requireFromUser` extensions
|
||||||
* `MedaGroupUpdate` and its direct extenders `SentMediaGroupUpdate` and `EditMediaGroupUpdate` became
|
* `MedaGroupUpdate` and its direct extenders `SentMediaGroupUpdate` and `EditMediaGroupUpdate` became
|
||||||
`sealed interface`s
|
`sealed interface`s
|
||||||
|
* New built-in `RequestException` implementator `GetUpdatesConflict` has been added
|
||||||
* `Behaviour Builder`:
|
* `Behaviour Builder`:
|
||||||
* ❗️ All triggers (`on*` extensions) have been modified to work in parallel by some marker by default (new parameter
|
* ❗️ 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)
|
`markerFactory`, in most cases will work async for different chats)
|
||||||
|
@ -24,6 +24,12 @@ fun newRequestException(
|
|||||||
plainAnswer,
|
plainAnswer,
|
||||||
message,
|
message,
|
||||||
cause
|
cause
|
||||||
|
),
|
||||||
|
description.contains("Conflict: terminated by other getUpdates request") -> GetUpdatesConflict(
|
||||||
|
response,
|
||||||
|
plainAnswer,
|
||||||
|
message,
|
||||||
|
cause
|
||||||
)
|
)
|
||||||
else -> null
|
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?) :
|
class TooMuchRequestsException(val retryAfter: RetryAfterError, response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||||
RequestException(response, plainAnswer, message, cause)
|
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.micro_utils.coroutines.*
|
||||||
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.bot.exceptions.GetUpdatesConflict
|
||||||
import dev.inmo.tgbotapi.bot.exceptions.RequestException
|
import dev.inmo.tgbotapi.bot.exceptions.RequestException
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
|
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
|
||||||
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
|
import dev.inmo.tgbotapi.extensions.utils.updates.lastUpdateIdentifier
|
||||||
@ -31,6 +32,9 @@ fun TelegramBot.longPollingFlow(
|
|||||||
if (e is RequestException) {
|
if (e is RequestException) {
|
||||||
delay(1000L)
|
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(
|
val updates = execute(
|
||||||
|
Loading…
Reference in New Issue
Block a user