Advertisement
Guest User

Simple TriHard spammer

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