Andrew-J-Larson / galnet-news-discord-bot

Gets news posts from Galnet News, for Elite Dangerous centered discord servers.
GNU General Public License v3.0
1 stars 1 forks source link

[Enhancement #3] Better post handling to avoid rate-limiting #8

Open Andrew-J-Larson opened 3 years ago

Andrew-J-Larson commented 3 years ago

Current implementation is fine for now, but rather a dirty fix...

It'd be better to use a sort of stack implementation for posting. Any bot posts/responses, would need to go onto the stack, and then the stack would correctly pop each post off under a correct amount of delay to avoid the rate-limiting (of 50 posts per second, at least globally).

The upside of doing this will remove the sometimes overuse of delay when it doesn't need to be used, aka making the bot faster again, even if slightly.

EDIT: I'm likely going to push this off until one of the bots has 50+ servers, because then it'll be absolute necessity.

Andrew-J-Larson commented 3 years ago

Biggest reason why

Because we may change rate limits at any time and rate limits can be different per application, rate limits should not be hard coded into your bot/application. In order to properly support our dynamic rate limits, your bot/application should parse for our rate limits in response headers and locally prevent exceeding the limits as they change.

Andrew-J-Larson commented 3 years ago

This will likely help with checking for rate limits that are active: https://www.codegrepper.com/code-examples/javascript/Check+ratelimit+discord+js

Andrew-J-Larson commented 3 years ago

Official documentation at https://discord.com/developers/docs/topics/rate-limits

Andrew-J-Larson commented 3 years ago

Oh, didn't know this, but apparently, Discord.js should be handling the rate-limits... https://github.com/discordjs/discord.js/issues/1637

In any case though, I still need to implement the message queue, as to check when messages aren't going through to attempt resends.