Fix: Respect sleep_threshold=0 in invoke() to prevent unwanted FloodWait sleep

This PR updates the `invoke()` method to correctly handle `sleep_threshold=0`.

### Before:
Even when `sleep_threshold=0`, the client still waits for the full FloodWait duration.

### After:
With this change:
- If `sleep_threshold == 0`, it raises the FloodWait immediately (no sleep).
- If `sleep_threshold < 0`, it always raises (never sleeps).
- If `sleep_threshold > 0`, it only sleeps if `amount <= sleep_threshold`.

This makes `sleep_threshold` behave more as expected and allows advanced bot handling logic outside of Pyrogram.

Thanks!
This commit is contained in:
fr0stb1rd 2025-07-11 16:01:24 +03:00 committed by GitHub
parent cf6141feb4
commit 5112e5da36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -421,7 +421,7 @@ class Session:
except (FloodWait, FloodPremiumWait) as e: except (FloodWait, FloodPremiumWait) as e:
amount = e.value amount = e.value
if amount > sleep_threshold >= 0: if sleep_threshold < 0 or amount > sleep_threshold:
raise raise
log.warning('[%s] Waiting for %s seconds before continuing (required by "%s")', log.warning('[%s] Waiting for %s seconds before continuing (required by "%s")',