Skip to content

Commit

Permalink
Merge pull request #7 from botlabs-gg/carl-bot-v2.0
Browse files Browse the repository at this point in the history
Carl bot v2.0
  • Loading branch information
amityadav-bst authored May 27, 2024
2 parents 8e99658 + 3982258 commit 872596f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ async def request(
remaining = response.headers.get("X-Ratelimit-Remaining")
if remaining == "0" and response.status != 429:
# we've depleted our current bucket
if response.status != 200 or response.status != 204:
print(f"RatelimitReached: status: {response.status}, url: {url}, method: {method}")
delta = utils._parse_ratelimit_header(
response, use_clock=self.use_clock
)
Expand All @@ -319,6 +321,7 @@ async def request(

# we are being rate limited
if response.status == 429:
print(f"APIRatelimitError: status: {response.status}, url: {url}, method: {method}")
if not response.headers.get("Via") or isinstance(data, str):
# Banned by Cloudflare more than likely.
raise HTTPException(response, data)
Expand All @@ -335,6 +338,7 @@ async def request(
# check if it's a global rate limit
is_global = data.get("global", False)
if is_global:
print(f"GlobalRateLimitReached: status: {response.status}, url: {url}, method: {method}")
_log.warning(
(
"Global rate limit has been hit. Retrying in"
Expand All @@ -361,6 +365,7 @@ async def request(
continue

# the usual error cases
print(f"APIError: status: {response.status}, url: {url}, method: {method}")
if response.status == 403:
raise Forbidden(response, data)
elif response.status == 404:
Expand Down

0 comments on commit 872596f

Please sign in to comment.