Advertisement
Guest User

Banned check

a guest
Sep 4th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var https = require('https');
  2. var irc = require('irc');
  3.  
  4. if (!Date.now) {
  5.     Date.now = function() { return new Date().getTime(); }
  6. }
  7.  
  8. var startTime;
  9. var num = 69;
  10. var totalNum = 0;
  11. var suffix = ".";
  12. var trihardCount = "0";
  13. var dispCount = false;
  14. var client;
  15. var prevCount = trihardCount;
  16. var intervalId = null;
  17. var updateCountIntervalId = null;
  18.  
  19. var bannedCheck = 0;
  20. var bannedTime;
  21.  
  22. var options = {
  23.     host: "twitchstats.io",
  24.     port: 443,
  25.     path: "/api/channel/ice_poseidon/initial",
  26.     method: "GET",
  27.     rejectUnauthorized: false
  28. };
  29.  
  30. function numberWithSpaces(x) {
  31.     return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
  32. }
  33.  
  34. function updateTriHardCount() {
  35.     var req = https.request(options, function(res){
  36.         res.on('data', function(d){
  37.             d = d.toString();
  38.             var index = d.indexOf(',"name":"TriHard"');
  39.             var end = index - 1;
  40.             while (d.charAt(--index) != ':') {}
  41.             trihardCount = d.substr(index+1, end-index);
  42.             req.destroy();
  43.         });
  44.     });
  45.     req.end();
  46.    
  47.     req.on('error', function(e){
  48.         console.error(e);
  49.     });
  50. }
  51.  
  52. function sendTriHards() {
  53.     if (prevCount == trihardCount) {
  54.         suffix += ".";
  55.         if (suffix == "....") {
  56.             suffix = ".";
  57.         }
  58.     } else {
  59.         prevCount = trihardCount;
  60.         suffix = ".";
  61.     }
  62.    
  63.     var msg = "";
  64.    
  65.     for (var i = 0; i < 33; i++)
  66.         msg += " TriHard";
  67.    
  68.     msg = "TriHard Count: " + numberWithSpaces(trihardCount);
  69.    
  70.     for (var i = 0; i < num; i++)
  71.         msg += " TriHard";
  72.  
  73.     totalNum += num;
  74.    
  75.     var seconds = (Date.now() - startTime) / 1000;
  76.     var time = "";
  77.     var weeks = Math.floor(seconds / 604800);
  78.     seconds = seconds - weeks * 604800;
  79.     var days = Math.floor(seconds / 86400);
  80.     seconds = seconds - days * 86400;
  81.     var hours = Math.floor(seconds / 3600);
  82.     seconds = seconds - hours * 3600;
  83.     var minutes = Math.floor(seconds / 60);
  84.     seconds = seconds - minutes * 60;
  85.    
  86.     if (weeks > 0) {
  87.         time += weeks + "w ";
  88.     }
  89.     if (days > 0) {
  90.         time += days + "d ";
  91.     }
  92.     if (hours > 0) {
  93.         time += hours + "h ";
  94.     }
  95.     if (minutes > 0) {
  96.         time += minutes + "m ";
  97.     }
  98.     if (seconds > 0) {
  99.         time += parseFloat(seconds).toFixed(3) + "s";
  100.     }
  101.    
  102.     client.say('#ice_poseidon', msg + suffix);
  103.     console.log("Posted " + num + " TriHards. Total TriHards: " + numberWithSpaces(trihardCount) + ". Total TriHards by this bot: " + totalNum + ".\tUptime: " + time + ".");
  104. }
  105.  
  106. function init() {
  107.     var config = {
  108.         channels: ['#ice_poseidon'],
  109.         username: '',
  110.         password: '',
  111.         floodProtection: false,
  112.         floodProtectionDelay: 2000
  113.     };
  114.     console.log("Fetched irc module.");
  115.     client = new irc.Client('irc.chat.twitch.tv', config.username, config);
  116.    
  117.     updateCountIntervalId = setInterval(updateTriHardCount, 2000);
  118.    
  119.     client.addListener('registered', function(message){
  120.         if (intervalId == null) {
  121.             updateTriHardCount();
  122.             startTime = Date.now();
  123.             intervalId = setInterval(sendTriHards, 2200);
  124.         } else {
  125.             if (bannedCheck == 0)
  126.                 bannedTime = Date.now();
  127.             if (Date.now() - bannedTime > 60000)
  128.                 bannedCheck = 0;
  129.             bannedCheck++;
  130.             if (bannedCheck == 5) {
  131.                 clearInterval(intervalId);
  132.                 clearInterval(updateCountIntervalId);
  133.                 client.disconnect();
  134.                 console.log("Probably banned...");
  135.             }
  136.         }
  137.     });
  138. }
  139.  
  140. init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement