EionRobb / purple-discord

A libpurple/Pidgin plugin for Discord
GNU General Public License v3.0
382 stars 43 forks source link

Rudimentary Ratelimiting, QoL Tweaks #378

Closed dlmarquis closed 3 years ago

dlmarquis commented 3 years ago

From #376:

The biggest change is some rudimentary ratelimiting that allows us to finally query missed group chat messages at startup. Experimentally, Discord has a 5-per-5-second limit on any given endpoint group (per channel, per guild, per webhook). The only place we run into that enough to cause serious problems is history fetching, so I added a 1-second delay before it fetches the next batch of messages. I also added a 30ms delay before any http fetch towards the end of not hitting the global ratelimit. The fetch process should also now abort and resend the request if it receives a code 429 ratelimit exceeded in the response header.

To make the history fetching experience a little better, I added channel settings that allow you to override whether a single channel is treated as large or small.

I also updated some enums, and added message type and permission flag enums to make the code a little less obtuse.

Outside of that, there are a few stray fixes to errors I've made in previous PRs.

EionRobb commented 3 years ago

Thanks for making the changes to the PR :)