#rate-limiting #discord #discord-api #twilight #sharding

twilight-gateway-queue

Discord Gateway connection queue implementation for the Twilight ecosystem

30 releases (15 breaking)

0.16.0-rc.1 Feb 21, 2024
0.15.4 Sep 10, 2023
0.15.2 Apr 27, 2023
0.15.1 Feb 26, 2023
0.2.1 Nov 10, 2020

#1869 in Web programming

Download history 831/week @ 2024-08-18 973/week @ 2024-08-25 953/week @ 2024-09-01 675/week @ 2024-09-08 756/week @ 2024-09-15 1067/week @ 2024-09-22 834/week @ 2024-09-29 454/week @ 2024-10-06 712/week @ 2024-10-13 990/week @ 2024-10-20 858/week @ 2024-10-27 778/week @ 2024-11-03 568/week @ 2024-11-10 781/week @ 2024-11-17 1061/week @ 2024-11-24 1307/week @ 2024-12-01

3,839 downloads per month
Used in 11 crates (2 directly)

ISC license

15KB
196 lines

twilight-gateway-queue

codecov badge discord badge github badge license badge rust badge

Rate limiting functionality for gateway IDENTIFY commands.

Discord allows bot's shards to send a limited amount of IDENTIFY commands every 5 seconds, with a daily limit from 1000 to 2000 commands, and invalidates all shard sessions upon exceeding it. Each identify interval may be filled by shards' IDs modulo max_concurrency and such a set of shards is called a bucket. See Discord Docs/Sharding.

To coordinate this, a Queue should process each identify request and shards should wait for its signal to proceed before continuing and otherwise retry. The provided InMemoryQueue never fails or cancels requests and is therefore a good starting point for custom implementations. It can also be composed to support multiple processes; see gateway-queue-http and gateway-queue for a HTTP client and server implementation, respectively.

Dependencies

~2.5–8.5MB
~68K SLoC