Twitch Spam

twitchbanner

Just felt like sharing a script I made for annoying/confusing people on Twitch. If you copy this and paste it in your browser’s console and run it while watching a Twitch stream, the script will post a random string at a set interval of seconds as defined by you in a prompt. The default is 15, and I believe setting it lower than 4 will cause Twitch to complain about you sending messages too quickly.

The strings that get posted at random are defined in the string table “strTable” variable. Just add, remove, or modify as desired. The script will also post back the last thing that anyone wrote in the chat log, addressed to that person and appended with a question mark. (Drawback to this is it could include addressing yourself as well.)

I do have a version that pipes the chat log over to an online bot service and then posts back the result (so people can effectively talk to an AI), but the service in question has API call limitations. To use that script one would have to modify the URLs embedded in the script–as well as have an AI service setup in the first place. I figure if you’re as crazy as me to do all that, then you could probably write the script from scratch yourself anyhow.

Without further adieu, here’s the code…

var i = 0;
var n = 0;
var nInterval = 15;

var strTable = [
"Hearty laughter is a good way to jog internally without having to go outdoors.",
"Marriage lets you annoy one special person for the rest of your life.",
"Never tease an armed midget with a high five.",
"Two days from now, tomorrow will be yesterday.",
"Life is a sexually transmitted condition.",
"Who?",
"I agree with that.",
"Why Lisa, why?!?",
"What a story, Mark! xD",
"I wonder if this script will pass the Turing test...",
"I still can't believe it's not butter!",
"What?",
"That's not how the Force works...",
"Go bake a pie in a fire.",
"Why thank you. Do you have any good jokes?",
"Would you like to know Dean Winchester?",
"Would I like to learn what?",
"What do you wish to lend me?",
"Your mom went to college.",
"Can you are more explicit.",
"Tell me more about your family.",
"You keep using that word; I do not think it means what you think it means.",
"Perhaps your childhood has something to do with this.",
"My pencil is big and yellow.",
"Do you know the babe?",
"That's what she said.",
"Holy rusted metal, Batman!",
"Cactus?",
"Cheesecake!",
"Indeed.",
"I used to be a man like you; then I took a Jenner to my wee.",
"Sometimes I think that dreams are the true reality and life is the simulacrum.",
"I still can't believe it's not butter!",
"No.",
"Just who do you think you are??",
"Do you have any idea who I am?!",
"You don't say?",
"Go on...",
"Really?",
"I know this one.",
"Why was W.S Gilbert frequently drunk on his transatlantic crossings? Because he was quartered... on the *port* side!",
"Blank"
];

nInterval = prompt("Enter the interval (in seconds) for the string randomizer:", nInterval);
if(isNaN(nInterval) || nInterval == null)
{
  alert("Process canceled.");
}
else
{
  alert("Running...");
  setInterval(function() { DoStuff(); }, nInterval * 1000);
}

function DoStuff(nInput)
{
  var iRandomNum;
  var iFlip = 0;
  iRandomNum = randomIntFromInterval(1,strTable.length);

  if(iRandomNum > (strTable.length / 2))
  {
    iFlip = randomIntFromInterval(1,2);
  }

  if(iFlip < 2)
  {
    $(".js-chat_input").val(strTable[iRandomNum]);
    $(".js-chat_input").trigger("change");
    document.getElementsByClassName("button float-right qa-chat-buttons__submit")[0].click();
  }
  else
  {
    RepeatBack();
  }
}

function randomIntFromInterval(min,max)
{
  return Math.floor(Math.random()*(max-min+1)+min);
}

function RepeatBack()
{
  var nLastMsgID = document.getElementsByClassName("message").length - 1;
  var nLastFromID = document.getElementsByClassName("from").length - 1;
  var sLastMsg = document.getElementsByClassName("message")[nLastMsgID].innerText;
  var sLastFrom = document.getElementsByClassName("from")[nLastFromID].innerText;
  if(sLastMsg.substr(sLastMsg.length - 1) == ".") sLastMsg = sLastMsg.substr(0, sLastMsg.length - 1);
  $(".js-chat_input").val("@" + sLastFrom + " " + sLastMsg + "?");
  $(".js-chat_input").trigger("change");
  document.getElementsByClassName("button float-right qa-chat-buttons__submit")[0].click(); 
}