5

If you type messages in chat rapidly enough, you'll start to get a cooldown:

A chat message with a "You can perform this action again in 22 seconds" response

I've been writing a chatbot library recently, and handling cooldowns is something that I've found a bit difficult. This library is what powers bots like Code Golf's New Posts and Sandbox Posts, which are important as they replace the feeds in Code Golf's main chat room. I've done close to an hour of experimenting with cooldowns, and I still can't tell what's going on.

I'd like to handle cooldowns in a way that prevents them from "stacking". Even after you wait out the cooldown, posting more messages quickly can cause it to return, often with a few seconds added. For bots with higher amounts of output, these cooldowns could chain, and enough messages could queue up during the previous cooldowns to freeze up the bot near permanently (this shouldn't happen in most applications, but because the cooldown is global, the right circumstances could definitely occur, such as in bots which respond to users' messages in multiple rooms).

I'm also slightly curious at this point, as while there's some obvious patterns to how the cooldowns work, it seems to occasionally just stop working the same way it did before, as if chat's just trying to mess with me.

I'm sure the specifics of how chat cooldowns work probably won't be revealed, since it could possibly be abused by spammers, but a little bit of information on how they work and how to avoid them causing issues would be really helpful.

9
  • 2
    It is detailed in the complete rate limiting guide: meta.stackexchange.com/questions/164899/…
    – rene
    Oct 22, 2021 at 20:31
  • @rene Interesting. It seems some information is either missing or changed, as I was able to get quite close to 40s rather than 20 as the graph would suggest. Thanks for that though, not sure how I didn't find it while searching! Oct 22, 2021 at 20:33
  • I don't get that popup in green, how do you get it like that?
    – bad_coder
    Oct 22, 2021 at 20:40
  • 1
    I do have a function I wrote 6 years ago isCurrentRateFine that is used by KennyBot. It takes an array with timestamps the bot posted and then tries to work out if it will be rate limited. I heavily commented that function so it is rather easy to follow what it does. ..... slowly backs away ....
    – rene
    Oct 22, 2021 at 20:41
  • 1
    @bad_coder Depends on the room (specifically, the site it's associated with). That message was in The Nineteenth Byte, CGCC's main room. Oct 22, 2021 at 20:41
  • 1
    The solution from a programmatic point of view is: 1. Try to post or edit the message. 2. If chat doesn't think you can post or edit yet, then you'll get an error response with the number of seconds you need to wait until you can post a message/edit. 3. Wait that number of seconds. 4. Go to 1.
    – Makyen
    Oct 22, 2021 at 23:24
  • @Makyen Nope. If you try doing that "by hand", you'll notice the cooldown increases each time, so you'll hit 20s between every message fairly quickly Oct 22, 2021 at 23:26
  • 1
    I've been doing it that way for years. In my testing, it's been the solution which has produced the most rapid posting of messages. Trying to pre-determine what chat wants has generally resulted in a substantially slower aggregate rate. Are you aware that you normally need no delay for every other message? What aggregate rate have you been seeing using your testing, over how many messages? Compared against what? Yes, if you keep banging away at it, the delays do continue to increase. There probably is a point at which it's better to completely stop, wait for a full reset, and start again.
    – Makyen
    Oct 22, 2021 at 23:36

0

Browse other questions tagged .