Fixed logic

This commit is contained in:
Frisk 2020-08-01 03:15:31 +02:00
parent 6731eea33d
commit ecf07a0534
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 3 additions and 2 deletions

View file

@ -138,7 +138,7 @@ async def send_to_discord_webhook(data: DiscordMessage, webhook_url: str) -> tup
async with aiohttp.ClientSession(headers=header, timeout=aiohttp.ClientTimeout(5.0)) as session: async with aiohttp.ClientSession(headers=header, timeout=aiohttp.ClientTimeout(5.0)) as session:
try: try:
result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data)) result = await session.post("https://discord.com/api/webhooks/"+webhook_url, data=repr(data))
rate_limit = None if int(result.headers.get('x-ratelimit-limit')) > 0 else result.headers.get('x-ratelimit-reset-after') rate_limit = None if int(result.headers.get('x-ratelimit-remaining')) > 0 else result.headers.get('x-ratelimit-reset-after')
except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError): except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError, TimeoutError):
logger.exception("Could not send the message to Discord") logger.exception("Could not send the message to Discord")
return 3, None return 3, None

View file

@ -47,8 +47,9 @@ class MessageQueue:
if status[0] < 2: if status[0] < 2:
logger.debug("Sending message succeeded") logger.debug("Sending message succeeded")
self._queue.remove(msg) self._queue.remove(msg)
logger.debug("Current rate limit time: {}".format(status[1]))
if status[1] is not None: if status[1] is not None:
await asyncio.sleep(float(status[1])) await asyncio.sleep(float(status[1])) # note, the timer on the last request won't matter that much since it's separate task and for the time of sleep it will give control to other tasks
else: else:
logger.debug("Sending message failed") logger.debug("Sending message failed")
break break