Advertisement
Guest User

error fixed

a guest
Sep 4th, 2016
134
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. var totalNum = 0;
  5. var num = 69;
  6. var suffix = ".";
  7. var trihardCount = "0";
  8. var dispCount = false;
  9. var client;
  10. var prevCount = trihardCount;
  11. var intervalId = null;
  12.  
  13. var options = {
  14.     host: "twitchstats.io",
  15.     port: 443,
  16.     path: "/api/channel/ice_poseidon/initial",
  17.     method: "GET",
  18.     rejectUnauthorized: false
  19. };
  20.  
  21. function numberWithSpaces(x) {
  22.     return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
  23. }
  24.  
  25. function updateTriHardCount() {
  26.     var req = https.request(options, function(res){
  27.         res.on('data', function(d){
  28.             d = d.toString();
  29.             var index = d.indexOf(',"name":"TriHard"');
  30.             var end = index - 1;
  31.             while (d.charAt(--index) != ':') {}
  32.             trihardCount = d.substr(index+1, end-index);
  33.             req.destroy();
  34.         });
  35.     });
  36.     req.end();
  37.    
  38.     req.on('error', function(e){
  39.         console.error(e);
  40.     });
  41. }
  42.  
  43. function sendTriHards() {
  44.     if (prevCount == trihardCount) {
  45.         suffix += ".";
  46.         if (suffix == "....") {
  47.             suffix = ".";
  48.         }
  49.     } else {
  50.         prevCount = trihardCount;
  51.         suffix = "";
  52.     }
  53.    
  54.     var msg = "";
  55.     for (var i = 0; i < 33; i++) {
  56.         msg += " TriHard";
  57.     }
  58.    
  59.     msg += " Count: " + numberWithSpaces(trihardCount);
  60.    
  61.     for (var i = 33; i < num; i++) {
  62.         msg += " TriHard";
  63.     }
  64.  
  65.     totalNum += num;
  66.    
  67.     client.say('#ice_poseidon', msg + suffix);
  68.     console.log("Sent TriHard x " + num + ". Total TriHards: " + numberWithSpaces(trihardCount) + ". Total TriHards by this bot: " + totalNum + ".");
  69. }
  70.  
  71. function init() {
  72.     var config = {
  73.         channels: ['#ice_poseidon'],
  74.         username: 'username here',
  75.         password: 'oauth:oauth key here',
  76.         floodProtection: false,
  77.         floodProtectionDelay: 2500
  78.     };
  79.     console.log("Fetched irc module.");
  80.     client = new irc.Client('irc.chat.twitch.tv', config.username, config);
  81.    
  82.     setInterval(updateTriHardCount, 2500);
  83.    
  84.     client.addListener('registered', function(message){
  85.         if (intervalId == null)
  86.             intervalId = setInterval(sendTriHards, 2500);
  87.     });
  88. }
  89.  
  90. init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement