Twitch Plays Pokemon - Command Filtering & Spamming Tool

Adds tools to your chatbox for spamming chat and filtering out commands from chat.

  1. // ==UserScript==
  2. // @name Twitch Plays Pokemon - Command Filtering & Spamming Tool
  3. // @namespace butt
  4. // @description Adds tools to your chatbox for spamming chat and filtering out commands from chat.
  5. // @include http://www.twitch.tv/twitchplayspokemon
  6. // @include http://beta.twitch.tv/twitchplayspokemon
  7. // @include http://www.twitch.tv/twitchplayspokemon/chat?popout=&secret=safe
  8. // @include http://beta.twitch.tv/twitchplayspokemon/chat?popout=&secret=safe
  9. // @version 1.12
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function tppmain() {
  14. var $ = window.$;
  15.  
  16. function setUpTheShit(){
  17. var spamhandle;
  18. var counterHandle;
  19. var autoSpam = true;
  20. var slowMode = true;
  21. var autoInterval = 30; //starting interval between spams
  22. var fastInterval = 6; //Guess at minimum interval that won't get you b&
  23. //var randomInterval = 30; //a random value up to this will be added to each timer
  24. var lastSpamTime = 0;
  25. var lastLastSpamTime = 0;
  26. var timeConfirmedSlow = timeSecs();
  27. var tryTime = 100; //seconds to wait before testing whether the room's slow again
  28. var timeBuffer = 2; //seconds to add to intervals, to avoid sending too fast
  29.  
  30. var stretchLetters = "aeioufjlmnrswy"; //Letters that can be randomly stretched
  31. var maxStretch = 12; //maximum extra letters to add
  32. var tooFastRegex = /This room is in slow mode and you are sending messages too quickly\. You will be able to talk again in (\d+) seconds\./;
  33. var genericTooFastRegex = /Your message was not sent because you are sending messages too quickly\./;
  34. var identicalRegex = /Your message was not sent because it is identical to the previous one you sent, less than (\d+) seconds ago\./;
  35. var slowModeRegex = /This room is now in slow mode\. You may send messages every (\d+) seconds/;
  36. var r9kRegex = /This room is in r9k mode and the message you attempted to send is not unique\.\sSee http:\/\/bit\.ly\/bGtBDf for more details\./;
  37. var bannedRegex = /You are banned from talking in twitchplayspokemon for (\d+) more seconds./;
  38. var inputRegex = /^((up|down|left|right|a|b|start|select|anarchy|democracy|wait|l|r|(\d+,\d+)|(!bet.+)?)(\+)?)+$/i;
  39. // Add buttons and shit
  40. $(".chat-interface").append('<div id="muh-controls" style="position:absolute;top:115px;padding:5px;"><label style="display:inline" for="dubs">Filter Inputs </label><input type="checkbox" id="dubs" checked><label style="display:inline" for="randomize"> Randomize Spam </label><input type="checkbox" id="randomize" checked><div><label for="spam-radio" style="display:inline">Spam: </label> <input type="radio" id="spam-radio" name="spam-radio" value="manual" title="Set spam intervals manually.">Manual <input type="radio" name="spam-radio" value="auto" title="Auto mode parses the chat to determine optimal intervals automatically.">Auto <input type="radio" name="spam-radio" value="none" checked title="Disable spamming."> None </div><div><label for="spam-text" style="display:inline">Text </label><input type="text" id="spam-text" value="guys we need to beat misty"></div><div><label for="spam-interval" style="display:inline">Interval(secs) </label><input type="text" id="spam-interval" value="32" style="width:50px"><span id="spam-counter"></span><span id="spam-notice" style="color:green"> You spammed!</span></div></div>');
  41. $(".chat-interface").css("bottom", "80px");
  42.  
  43. // FILTERING
  44. var showAll = false;
  45. $("#dubs").click( function() {
  46. showAll = !showAll;
  47. } );
  48.  
  49. function randomChecked() {
  50. return ( $("#randomize:checked").size() > 0 );
  51. }
  52. amShit = function (str) {
  53. return str.match(inputRegex);
  54. };
  55. var addMessage = App.Room.prototype.addMessage;
  56. window.adminMsgs = new Array();
  57. App.Room.prototype.addMessage = function (anus) {
  58. if (showAll || !amShit($.trim(anus.message.toLowerCase()))) {
  59. addMessage.call(this, anus);
  60. }
  61. if(anus.style === "admin") {
  62. window.adminMsgs.push(anus);
  63. //console.log(anus.message);
  64. handleAdminMsg(anus);
  65. }
  66. };
  67. handleAdminMsg = function(msg) {
  68. var tooFastBy, slowModeTime, identicalTime;
  69.  
  70. //Only read admin messages in auto-spam mode
  71. if(!autoSpam) return;
  72.  
  73. //Catch if we posted too fast
  74. if( (tooFastBy = tooFastRegex.exec(msg.message)) !== null ) {
  75. tooFastBy = parseInt(tooFastBy[1]);
  76. //Post again after time
  77. spamIn(tooFastBy);
  78. tooFastTime = lastSpamTime - lastLastSpamTime;
  79. enterSlowMode(tooFastTime + tooFastBy);
  80. console.log("Too fast by " + tooFastBy);
  81. }
  82. else if(msg.message.match(genericTooFastRegex)) {
  83. setAutoInterval(autoInterval * 2);
  84. console.log("Generically too fast!");
  85. }
  86. else if(msg.message.match(r9kRegex)) {
  87. if( randomChecked() ) {
  88. spamIn(1);
  89. }
  90. console.log("r9k-blocked");
  91. }
  92. else if( (identicalTime = identicalRegex.exec(msg.message)) !== null) {
  93. //Does this mean we're in slow mode? Let's assume yes.
  94. identicalTime = parseInt(identicalTime[1]);
  95. tooFastTime = lastSpamTime - lastLastSpamTime;
  96. canSpamIn = identicalTime - tooFastTime;
  97. spamIn(canSpamIn);
  98. if( !randomChecked() ) {
  99. enterSlowMode(identicalTime); //If input not randomized, gotta slow down
  100. }
  101. console.log("Identical message! Time:"+identicalTime+". Only waited: "+tooFastTime+". Resend in " + canSpamIn); //30-0-30??
  102. }
  103. else if( (slowModeTime = slowModeRegex.exec(msg.message)) !== null) {
  104. slowModeTime = parseInt(slowModeTime[1]);
  105. //Update auto-timer
  106. enterSlowMode(slowModeTime);
  107. console.log("Entered slow mode!");
  108. }
  109. else if( (bannedTime = bannedRegex.exec(msg.message)) !== null) {
  110. bannedTime = parseInt(bannedTime[1]);
  111. //Try not spamming so fast
  112. if(autoInterval == fastInterval) {
  113. fastInterval += 3;
  114. console.log("Increasing fast interval to "+fastInterval);
  115. }
  116. spamIn(bannedTime);
  117. enterSlowMode(30);
  118. console.log("b& for " + bannedTime);
  119. }
  120. else {
  121. console.log(msg.message);
  122. }
  123. }
  124. enterSlowMode = function(time) {
  125. if(time > fastInterval){
  126. slowMode = true;
  127. setAutoInterval(time);
  128. }
  129. else {
  130. setAutoInterval(fastInterval);
  131. }
  132. timeConfirmedSlow = timeSecs();
  133. }
  134.  
  135. function setAutoInterval(time) {
  136. time = Math.floor(time);
  137. autoInterval = time;
  138. if(autoSpam){
  139. $("input#spam-interval").val(time + timeBuffer);
  140. }
  141. }
  142.  
  143. //Returns new spam interval in seconds
  144. decideInterval = function() {
  145. var timeSinceConfirmedSlow = (timeSecs() - timeConfirmedSlow);
  146. if(slowMode && timeSinceConfirmedSlow > tryTime) {
  147. console.log("Checking if still slow...");
  148. slowMode = false;
  149. setAutoInterval(fastInterval);
  150. }
  151.  
  152. //Randomize interval
  153. //if(autoInterval == fastInterval) {
  154. //addToInterval = Math.floor( Math.random() * randomInterval );
  155. //return autoInterval + addToInterval;
  156. //}
  157. return autoInterval;
  158. }
  159. // SPAMMING
  160. $("#spam-notice").hide();
  161. function spam(){
  162. var textbox = $(".chat-interface .textarea-contain textarea");
  163. var old_shit = textbox.val();
  164. var text = $("#spam-text").val().toString();
  165. if( !amShit(text) && $("#randomize:checked").size() > 0) {
  166. text = randomize(text);
  167. }
  168. textbox.val(text);
  169. textbox.focus().blur();
  170. $(".send-chat-button button")[0].click();
  171. lastLastSpamTime = lastSpamTime;
  172. lastSpamTime = timeSecs();
  173. $("#spam-notice").show();
  174. $("#spam-notice").fadeOut(3000);
  175. textbox.val(old_shit);
  176. var interval = autoSpam ? decideInterval() : parseInt($("#spam-interval").val());
  177. spamIn(interval);
  178. }
  179.  
  180. //randomly elongates vowels in string
  181. function randomize(str) {
  182. var indices = new Array();
  183. for(i=0; i < str.length; i++) {
  184. ch = str[i].toLowerCase();
  185. if (stretchLetters.indexOf(ch) != -1) {
  186. indices.push(i);
  187. }
  188. }
  189. if(indices.length == 0) return str;
  190. var indA = indices[Math.floor( Math.random() * indices.length )];
  191. var indB = indices[Math.floor( Math.random() * indices.length )];
  192. if(indB < indA) {temp = indA; indA = indB; indB = temp;} //B is the higher index
  193. var duplicateABy = Math.floor( Math.random() * (maxStretch) + 1);
  194. var extraStringA = str[indA].repeat(duplicateABy);
  195. var duplicateBBy = Math.floor( Math.random() * (maxStretch) + 1);
  196. var extraStringB = str[indB].repeat(duplicateBBy);
  197. if(indB == indA) extraStringB = "";
  198. return str.slice(0,indA) + extraStringA + str.slice(indA, indB) + extraStringB + str.slice(indB);
  199. }
  200.  
  201. //sets timer to spam, in seconds
  202. function spamIn(interval) {
  203. if(autoSpam) interval += timeBuffer;
  204. interval = Math.floor(interval);
  205. clearTimeout(spamhandle);
  206. spamhandle = setTimeout(spam, interval * 1000);
  207. counter($("#spam-counter"), interval);
  208. }
  209. //Returns "manual", "auto", or "none" based on radio buttons
  210. function getSpamMode() {
  211. return $("input:radio[name=spam-radio]:checked").val();
  212. }
  213. $("input:radio[name=spam-radio]").change(function(){
  214. var timeSince = timeSecs() - lastSpamTime;
  215.  
  216. if(getSpamMode() === "manual") {
  217. autoSpam = false;
  218. $("input#spam-interval").removeAttr("disabled");
  219. clearTimeout(spamhandle);
  220. var interval = parseInt($("#spam-interval").val());
  221. if(timeSince < interval) {
  222. spamIn(interval - timeSince);
  223. }
  224. else spam();
  225. }
  226. else if(getSpamMode() === "auto") {
  227. autoSpam = true;
  228. $("input#spam-interval").attr("disabled", "true");
  229. clearTimeout(spamhandle);
  230. setAutoInterval(autoInterval);
  231. if(timeSince < autoInterval) {
  232. spamIn(autoInterval - timeSince);
  233. }
  234. else spam();
  235. }
  236. else if(getSpamMode() === "none") {
  237. autoSpam = false;
  238. $("input#spam-interval").removeAttr("disabled");
  239. clearTimeout(spamhandle);
  240. clearTimeout(counterHandle);
  241. $("#spam-counter").hide();
  242. }
  243. });
  244. //sets counter, in seconds
  245. function counter($el, n) {
  246. $("#spam-counter").show();
  247. clearTimeout(counterHandle);
  248. (function loop() {
  249. $el.html(n);
  250. if (n--) {
  251. counterHandle = setTimeout(loop, 1000);
  252. }
  253. })();
  254. }
  255.  
  256. function timeSecs() {
  257. var deito = new Date();
  258. return deito.getTime() / 1000;
  259. }
  260. //Need this for chrome
  261. String.prototype.repeat = function( num ) {
  262. return new Array( num + 1 ).join( this );
  263. }
  264. $(window).resize();
  265. }
  266.  
  267. function loopydoo (){
  268. if ( typeof($) == "function" && document.readyState == 'complete' && $("div.chat-interface").size() > 0 ) {
  269. setUpTheShit();
  270. }
  271. else {
  272. setTimeout(loopydoo, 500);
  273. }
  274. }
  275.  
  276. loopydoo();
  277.  
  278. }
  279.  
  280. //Inject dat shit nigga aaawwww yiss
  281. var script = document.createElement('script');
  282. script.textContent = '(' + tppmain.toString() + ')();';
  283. document.body.appendChild(script);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址