which is hinting to me that the connection got closed on Twitch’s end.
The bot is not getting banned so I assume it is not hitting the PRIVMSG limit. Maybe another limit which I am not aware of? Or could being not a known/verified bot an issue?
Here some context:
3 message pools are running.
Runs every ~ 330ms
handles the sending of authentication and joining messages (NICK, PASS, CAP REQ, JOIN, PART)
Is connection independent
Every message gets send with the corresponding connection.
Maximum 1 message each iteration.
Runs every ~ 1530ms
Handles the sending of PRIVMSG messages to channels without MODERATOR privilege.
Iterates through VIEWER privilege connections and sends 1 message for each connection and iteration.
Runs every ~ 330ms
Handles the sending of PRIVMSG messages to channels with MODERATOR privilege.
Iterates through MODERATOR privilege connections and sends 1 message for each connection and iteration.
Every connection holds only one type of channel (VIEWER, MODERATOR). This is depending on the channel role of the bot. A VIEWER connection holds 90 channels, a MODERATOR connection holds 70 channels at max.
I tried different iteration times and channel limits per connection, but at one point im getting the error.
Once every 300ms amounts to 100 in 30 seconds, which is the current limit for channel moderators. The send limits are per account, so additional connections on the same account having their own independent rate limiting is going to break.
You can also only rely on having the mod limits if you 100% trust the broadcaster(s) using your bot not to unmod it while it’s above the non-mod limit.
My bad, i have implemented the PING PONG. I didnt mention it because the error occurs before the first PING arrrives.
You mean other than message/whisper limits? In the test-case the bot sends 100 JOINS and “.mods” commands to get the moderator list of each channel. 245 messages in total.
I am really suprised that the message limit is per bot account. I thought it is per connection. How can you handle (even with verified state) a lot of channels (500+) at the same time? Not that I am in that range, I just want to implement it correctly.
Currently i am kind of working around this by reacting to
:jtv MODE #channel -o user
message and move (part and rejoin) the channel to a connection with VIEWER iteration and the other way around. But it feels not reliable since the bot might react during the transition time and maybe the MODE message is not received or to late.
The link I provided to the command & message limitations are referring to what is being sent from you to the server.
What Twitch doesn’t disclose on their API are their limitations of the amount of data being sent from the server to you.
For example, back when I made a bot a few years ago. I was messing with the API to retrieve the top channels on twitch. By top, I mean the channels with the most viewers and I could only ever join 48 channels before getting disconnected. From there I realized that the disconnection was intentional because when you have twitch sending potentially 100K+ messages/second from chatters that is too much for them to be sending you lol. I am not sure if they raised the limit or not but that is also something to consider when making a bot that might be handling large channels.
Funny that you mention this. That was exactly my test case. . Twitch must have increased the receiving limit. I got the top100 channel messages with a single connection. I dont know if some messages got dropped becasue i didnt receive a massive amount of chat messages.
The error only oocurs if i am adding more connections. So it must have sth to do with my implementation of the sending limits. 3ventic mentioned that the limits are account related. That is really confusing me. How can you handle than >500 channels, if you want to moderate them proper. Even if you are a verified bot there is a ceiling.
JOINs are rate-limited to 50 JOINs per 15 seconds. So you need to spread them out. Big bots like moobot take hours to rejoin on full reboot and usually offer “priority” to donors. I think there are higher limits for verified bots but I do not see that documented anywhere.
It used to be per connection but was changed to per account within the last year due to abuse. I recommend spreading out commands to stay within the limit. For example there is very little reason to run “.mods” when joining a channel unless you need to display the full list. For access control just use IRC v3 tags.
There is an internal buffer on the socket sending data to you. If you fill that buffer because you are not reading messages fast enough that it will disconnect. This is why most people still use multiple connections even after the rate limits were changed to per account.