kritzware/twitch-bot

Rate Limiting Feature Discussion

Opened this issue · 1 comments

As pointed out in the feature suggestion issue, seamless rate limitation is important for the usability of the bot. I think it's a good idea to dedicate an issue to this feature in order to discuss an approach for implemetnation.

The rate limitation threshold depends on the Bot's user status in the channel:

  • 20 per 30 seconds, if not mod / operator
  • 100 per 30 seconds if mod / operator
  • 50 per 30 seconds for known bots
  • 7500 per 30 seconds for known bots

Source

This requires to introduce a new data structure that fulfills the following tasks:

  • keep track of messages sent in a particular channel
  • if rate limit is reached, buffer messages in a FIFO queue and send them whenever a message slot becomes available again
  • keep track of the Bot's user level
  • keep track of a reference to the say-function so it can decide on its own when to send buffered messages

A useful data structure for implementation is a circular buffer.

In the future this data structure can also be used to save channel-specific information like current users.

Standalone working sample implementation:
https://gist.github.com/anXieTyPB/66622eae5c0da2a37869bfbed055a5d2

npm install circular-buffer
run.