Created
February 13, 2013 00:59
-
-
Save pantlesswonder/4780321 to your computer and use it in GitHub Desktop.
Workaround for plug.dj rate limiting and bots being easily banned
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ok so this is pretty neat, you can just burst two messages every just over 3.33 seconds, | |
//and you never hit the rate limiter to cause the banning. Very groovy. | |
//constants | |
var delay = 3400, //ms to wait per burst | |
burst = 2; //burst the first 2 messages | |
//state | |
var messages = [], | |
timer = null; | |
function send(msg) | |
{ | |
messages.push(msg); | |
if (null == timer) | |
{ | |
timer = true; | |
//brief pause so we can burst more than one message | |
setTimeout(function(){ | |
timer = setInterval(sendTick, delay); //set ourselves to run in the future | |
sendTick(); //start immediately too | |
}, 20); | |
} | |
} | |
function sendTick() | |
{ | |
//send up to burst messages each go-round | |
for (var i=burst; i>0; i--) | |
{ | |
var msg = messages.shift(); | |
if (msg) | |
{ | |
//SEND MESSAGE FOR REAL HERE | |
} | |
} | |
//stop if we're done | |
if (0 == messages.length) | |
{ | |
clearInterval(timer); | |
timer = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment