mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Fixed logic
This commit is contained in:
parent
6731eea33d
commit
ecf07a0534
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue