Advertisement
Hirsw0w

Untitled

Apr 17th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. // settings
  2. var active = true;
  3. var min = 0;
  4. var max = 100000;
  5. var channel = "";
  6.  
  7. // cookies
  8. var oauth = getCookie("auth-token");
  9. var name = getCookie("name");
  10. var login = getCookie("login");
  11.  
  12. var captures = [];
  13.  
  14. var socket = undefined;
  15. ConnectSocket();
  16.  
  17. function ConnectSocket() {
  18. socket = new WebSocket("wss://irc-ws.chat.twitch.tv/");
  19.  
  20. socket.onopen = function (e) {
  21. socket.send("CAP REQ :twitch.tv/tags twitch.tv/commands");
  22. socket.send("PASS oauth:" + oauth);
  23. socket.send("NICK " + name);
  24. socket.send("USER " + login + " 8 * :" + login);
  25. socket.send("JOIN #" + channel);
  26. }
  27.  
  28. socket.onmessage = function (event) {
  29. var msg = event.data;
  30. if (msg.indexOf("PING :tmi.twitch.tv") != -1) {
  31. socket.send("PONG");
  32. return;
  33. }
  34.  
  35. if (msg.indexOf("@badge-info=") == -1)
  36. return;
  37.  
  38. /* if(!active)
  39. return;*/
  40.  
  41. var regex = /:(.*)\!.*@.*\.tmi\.twitch\.tv PRIVMSG #([^:]*):(.*)/;
  42. var matches = regex.exec(msg);
  43. if (matches == null || matches == undefined || matches.length < 4)
  44. return;
  45.  
  46. var num = parseInt(matches[3]);
  47. if (Number.isNaN(num))
  48. return;
  49.  
  50. captures.push(num);
  51. }
  52.  
  53. socket.onclose = function (e) {
  54. console.log("closed connection!");
  55. setTimeout(function () {
  56. ConnectSocket();
  57. }, 2000);
  58. }
  59.  
  60. }
  61.  
  62.  
  63. setInterval(function() {
  64. if(!active || socket.readyState != socket.OPEN)
  65. return;
  66.  
  67. var num = getRandomNumber();
  68. captures.push(num);
  69. socket.send("PRIVMSG #" + channel + " :" + num);
  70. console.log("Typing number: " + num);
  71. }, 1000);
  72.  
  73.  
  74. setInterval(function () {
  75. socket.send("PING");
  76. }, 30000);
  77.  
  78. function reset() {
  79. captures = [];
  80. }
  81.  
  82. function totalCaptures() {
  83. console.log("Total Captures: " + captures.length);
  84. }
  85.  
  86. function getRandomNumber() {
  87. var num = Math.floor(Math.random() * (max - min)) + min;
  88. while(captures.includes(num))
  89. num = Math.floor(Math.random() * (max - min)) + min;
  90.  
  91. return num;
  92. }
  93.  
  94. function getCookie(name) {
  95. var value = "; " + document.cookie;
  96. var parts = value.split("; " + name + "=");
  97. if (parts.length == 2) return parts.pop().split(";").shift();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement