Browse Source

Use new rate limit millisecond precision option.

pull/2327/head
Rapptz 6 years ago
parent
commit
078d1d71d8
  1. 15
      discord/http.py
  2. 2
      discord/utils.py

15
discord/http.py

@ -105,7 +105,7 @@ class HTTPClient:
if self.__session.closed:
self.__session = aiohttp.ClientSession(connector=self.connector, loop=self.loop)
async def request(self, route, *, files=None, header_bypass_delay=None, **kwargs):
async def request(self, route, *, files=None, **kwargs):
bucket = route.bucket
method = route.method
url = route.url
@ -119,6 +119,7 @@ class HTTPClient:
# header creation
headers = {
'User-Agent': self.user_agent,
'X-Ratelimit-Precision': 'millisecond',
}
if self.token is not None:
@ -165,11 +166,7 @@ class HTTPClient:
remaining = r.headers.get('X-Ratelimit-Remaining')
if remaining == '0' and r.status != 429:
# we've depleted our current bucket
if header_bypass_delay is None:
delta = utils._parse_ratelimit_header(r)
else:
delta = header_bypass_delay
delta = utils._parse_ratelimit_header(r)
log.debug('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta)
maybe_lock.defer()
self.loop.call_later(delta, lock.release)
@ -383,17 +380,17 @@ class HTTPClient:
def add_reaction(self, channel_id, message_id, emoji):
r = Route('PUT', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
channel_id=channel_id, message_id=message_id, emoji=emoji)
return self.request(r, header_bypass_delay=0.25)
return self.request(r)
def remove_reaction(self, channel_id, message_id, emoji, member_id):
r = Route('DELETE', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/{member_id}',
channel_id=channel_id, message_id=message_id, member_id=member_id, emoji=emoji)
return self.request(r, header_bypass_delay=0.25)
return self.request(r)
def remove_own_reaction(self, channel_id, message_id, emoji):
r = Route('DELETE', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
channel_id=channel_id, message_id=message_id, emoji=emoji)
return self.request(r, header_bypass_delay=0.25)
return self.request(r)
def get_reaction_users(self, channel_id, message_id, emoji, limit, after=None):
r = Route('GET', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}',

2
discord/utils.py

@ -304,7 +304,7 @@ def to_json(obj):
def _parse_ratelimit_header(request):
now = parsedate_to_datetime(request.headers['Date'])
reset = datetime.datetime.fromtimestamp(int(request.headers['X-Ratelimit-Reset']), datetime.timezone.utc)
reset = datetime.datetime.fromtimestamp(float(request.headers['X-Ratelimit-Reset']), datetime.timezone.utc)
return (reset - now).total_seconds()
async def maybe_coroutine(f, *args, **kwargs):

Loading…
Cancel
Save