Skip to content

Commit

Permalink
bulk: merge Doru's suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: VincentRPS <[email protected]>
  • Loading branch information
VincentRPS and Dorukyum authored Jan 4, 2024
1 parent ba3c20f commit 6c1465f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ class Client:
Defaults to `1` second.
.. versionadded:: 2.5
maximum_rate_limit_time: :class:`int`
The maximum amount of seconds the client is allowed to wait on a rate limit,
or otherwise error out. Defaults to `-1`, or infinite.
rate_limit_timeout: :class:`float`
The maximum amount of seconds the client is allowed to wait on a rate limit
before raising an exception. Defaults to `-1`, or infinite.
.. versionadded:: 2.5
Expand Down Expand Up @@ -251,6 +251,7 @@ def __init__(
bucket_storage = options.pop("bucket_storage_cls", BucketStorage)(
options.pop("per", 1), options.pop("concurrency", 50)
)
rate_limit_timeout: float = options.pop("rate_limit_timeout", -1)

self.http: HTTPClient = HTTPClient(
bucket_storage,
Expand All @@ -259,7 +260,7 @@ def __init__(
proxy_auth=proxy_auth,
unsync_clock=unsync_clock,
loop=self.loop,
maximum_rate_limit_time=options.pop("maximum_rate_limit_time", -1),
rate_limit_timeout=rate_limit_timeout,
)

self._handlers: dict[str, Callable] = {"ready": self._handle_ready}
Expand Down
12 changes: 6 additions & 6 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(
proxy_auth: aiohttp.BasicAuth | None = None,
loop: asyncio.AbstractEventLoop | None = None,
unsync_clock: bool = True,
maximum_rate_limit_time: int | float = -1,
rate_limit_timeout: float = -1,
) -> None:
self.loop: asyncio.AbstractEventLoop = (
asyncio.get_event_loop() if loop is None else loop
Expand All @@ -156,7 +156,7 @@ def __init__(
self.proxy: str | None = proxy
self.proxy_auth: aiohttp.BasicAuth | None = proxy_auth
self.use_clock: bool = not unsync_clock
self.maximum_rate_limit_time = maximum_rate_limit_time
self.rate_limit_timeout = rate_limit_timeout

user_agent = (
"DiscordBot (https://pycord.dev, {0}) Python/{1[0]}.{1[1]} aiohttp/{2}"
Expand Down Expand Up @@ -313,12 +313,12 @@ async def request(
is_global: bool = data.get("global", False)

if (
retry_after > self.maximum_rate_limit_time
and self.maximum_rate_limit_time != -1
retry_after > self.rate_limit_timeout
and self.rate_limit_timeout != -1
):
raise HTTPException(
response,
f"Retrying rate limit would take longer than the maximum of {self.maximum_rate_limit_wait_time} seconds given",
f"Retrying rate limit would take longer than the maximum of {self.rate_limit_timeout} seconds given",
)

if is_global:
Expand Down Expand Up @@ -346,7 +346,7 @@ async def request(
continue

# we've received a 500, 502, or 504, unconditional retry
if response.status in {500, 502, 504}:
if response.status in (500, 502, 504):
await asyncio.sleep(1 + tries * 2)
continue

Expand Down

0 comments on commit 6c1465f

Please sign in to comment.