@@ -442,19 +442,21 @@ class Ratelimit:
442
442
'dirty' ,
443
443
'_last_request' ,
444
444
'_max_ratelimit_timeout' ,
445
+ '_default_ratelimit_limit' ,
445
446
'_loop' ,
446
447
'_pending_requests' ,
447
448
'_sleeping' ,
448
449
)
449
450
450
- def __init__ (self , max_ratelimit_timeout : Optional [float ]) -> None :
451
- self .limit : int = 1
451
+ def __init__ (self , max_ratelimit_timeout : Optional [float ], default_ratelimit_limit : int ) -> None :
452
+ self .limit : int = default_ratelimit_limit
452
453
self .remaining : int = self .limit
453
454
self .outgoing : int = 0
454
455
self .reset_after : float = 0.0
455
456
self .expires : Optional [float ] = None
456
457
self .dirty : bool = False
457
458
self ._max_ratelimit_timeout : Optional [float ] = max_ratelimit_timeout
459
+ self ._default_ratelimit_limit : int = default_ratelimit_limit
458
460
self ._loop : asyncio .AbstractEventLoop = asyncio .get_running_loop ()
459
461
self ._pending_requests : deque [asyncio .Future [Any ]] = deque ()
460
462
# Only a single rate limit object should be sleeping at a time.
@@ -476,7 +478,7 @@ def reset(self):
476
478
477
479
def update (self , response : Union [aiohttp .ClientResponse , requests .Response ], * , use_clock : bool = False ) -> None :
478
480
headers = response .headers
479
- self .limit = int (headers .get ('X-Ratelimit-Limit' , 1 ))
481
+ self .limit = int (headers .get ('X-Ratelimit-Limit' , self . _default_ratelimit_limit ))
480
482
481
483
if self .dirty :
482
484
self .remaining = min (int (headers .get ('X-Ratelimit-Remaining' , 0 )), self .limit - self .outgoing )
@@ -603,6 +605,7 @@ def __init__(
603
605
unsync_clock : bool = True ,
604
606
captcha : Optional [Callable [[CaptchaRequired ], Coroutine [Any , Any , str ]]] = None ,
605
607
max_ratelimit_timeout : Optional [float ] = None ,
608
+ default_ratelimit_limit : int = 1 ,
606
609
locale : Callable [[], str ] = lambda : 'en-US' ,
607
610
extra_headers : Optional [Mapping [str , str ]] = None ,
608
611
debug_options : Optional [Sequence [str ]] = None ,
@@ -633,6 +636,7 @@ def __init__(
633
636
self .use_clock : bool = not unsync_clock
634
637
self .captcha_handler : Optional [Callable [[CaptchaRequired ], Coroutine [Any , Any , str ]]] = captcha
635
638
self .max_ratelimit_timeout : Optional [float ] = max (30.0 , max_ratelimit_timeout ) if max_ratelimit_timeout else None
639
+ self .default_ratelimit_limit : int = default_ratelimit_limit
636
640
self .get_locale : Callable [[], str ] = locale
637
641
self .extra_headers : Mapping [str , str ] = extra_headers or {}
638
642
self .debug_options : Optional [Sequence [str ]] = debug_options
@@ -732,7 +736,7 @@ def get_ratelimit(self, key: str) -> Ratelimit:
732
736
try :
733
737
value = self ._buckets [key ]
734
738
except KeyError :
735
- self ._buckets [key ] = value = Ratelimit (self .max_ratelimit_timeout )
739
+ self ._buckets [key ] = value = Ratelimit (self .max_ratelimit_timeout , self . default_ratelimit_limit )
736
740
self ._try_clear_expired_ratelimits ()
737
741
return value
738
742
0 commit comments