Just submitted for bot whitelist. Still have questions though!

I just saw a thread by xangold where we can whitelist our bots for increased messaging rates.

Currently, as I interpreted the rules, there are general limitations to your chatting features.
-You can only send 20 msgs/30 sec if you’re a normal user
-You can only send 100 msg/30 sec if you’re a moderator

The thread said if we get ours bots whitelisted, the 20 will be bumped up to 50.
What about is my bot is a mod? Does it bump up any higher?

And apparently, if you hit over that limit, even barely, twitch will blacklist you for 8 hours from sending any messages. So I’m guessing I’ll have to count my responses and remove them systematically after 30 seconds as to not exceed that limit in any scenario, despite it probably never happening.

Is this all correct?

Correct, except the time is not 8 hours anymore, it’s 30 minutes. What I do in my bot currently is have a message queue that drains at a stable rate (sleeping a certain amount of milliseconds between each message).

1 Like

But then aren’t you adding an unnecessary delay for your messages?

Rarely ever would a bot send > 50 or 100 messages in 30 seconds, seems like a bad solution honestly.

It would be better to have an int variable that gets incremented whenever a new message is sent. When the message is sent, it also executes a new thread which sleeps for 30 seconds, decrements the integer variable, and then the thread would be expired and cleaned up.

Of course whenever you would be sending messages, you’d also have to make sure the integer was below 100/50 depending on whether you’re a mod or not in the channel.

If your bot is in 2 channels, sends 50 messages in a channel where it is modded, then 1 in a channel where it is not, you just triggered a global/IP ban. Just make sure you are aware of your current message rate to the server on that connection(IP Based). There are a variety of ways to handle it. To each their own.

FYI, rate limits are now per account and not connection.

Thanks for the info.

Thanks, that’s very useful info.

How does Nightbot get through this? I’m guessing Twitch just gives Nightbot and other popular bots special permissions?

Returning back with a solution you might want to consider implementing.

My solution uses Java, and since Java is benefitted with syncronized methods and volatile variables, if you are considering porting my code into C or any other programming language obviously you’re going to have to use a mutex to lock the variable directly, or consider a counting lock. Just make sure you know what atomic instructions are.


class MessageSender implements Runnable{

public static volatile int flood = 0;
public static final int FLOOD_LIMIT = 100;

private BotController botController; //This is another class I created which controls my bot
private String message;

public synchronized static void decrementFlood(){
    flood -= 1;
    System.out.println("[Decremented] Flood: " + flood);
}

public synchronized static void incrementFlood(BotController botController, String message){
    flood += 1;
    botController.getBot().send().message(botController.CHANNEL, message);
    System.out.println("[Incremented] Flood: " + flood);
}

public MessageSender(BotController botController, String message) {
    //This is just a constructor
    this.botController = botController;
    this.message = message;
}

@Override
public void run() {
    if (flood == FLOOD_LIMIT){ 
        while(flood == FLOOD_LIMIT){
            try{
                Thread.sleep(1000); //Can be replaced with executor services to determine when threads end
            } catch (InterruptedException ex ){
                System.out.println("Interrupted Thread error, this would imply you aborted the program.");
            }
        }
    }

    incrementFlood(botController, message);
    Thread decrementThread = new Thread(new GameTimer(30, true)); //This is just a timer I made to count to 30 and then decrement
    decrementThread.start();
}
}

I made this class, designed to be executed through a thread or thread pool (hence why I implemented Runnable)
So here’s my implementiation:

 public static void sendMessage(BotController botController, String message){
    Thread messageThread = new Thread(new MessageSender(botController, message));
    messageThread.start();
}

I ran tests already with this and it works well. You could probably further upgrade my example by creating a fixed size thread pool of 100, and cast jobs of sending messages on them, waiting 30 seconds, and terminating them. You could then possibly handle the thread pool with an executor service, which might be beneficial if you want to know exactly when your threads exit, rather than sleep-waiting for threads to finish. The reason I chose to sleep-wait is because it far less CPU output than an executor, event driven listening service.

Toodles.

1 Like

We do whitelist very popular bots (whitelist = higher rate limits).

In general, for rate limits you want to implement what is called a “sliding window”. What you do, is have a sorted set of items sorted by time. Then, when sending a message you check how many items were sent within that time period, and decide to remove that item and send it, or wait to send.

What @3ventic said about just waiting a set period of ms between messages works as well (albeit doesn’t allow for bursts of messages within a period). If you don’t expect to send more than 1 message per 1.5 seconds, then this is the easiest thing to implement.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.