Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var https = require('https');
- var irc = require('irc');
- var totalNum = 0;
- var num = 69;
- var suffix = "";
- var trihardCount = "0";
- var dispCount = false;
- var client;
- var prevCount = trihardCount;
- var options = {
- host: "twitchstats.io",
- port: 443,
- path: "/api/channel/ice_poseidon/initial",
- method: "GET",
- rejectUnauthorized: false
- };
- function numberWithSpaces(x) {
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
- }
- function updateTriHardCount() {
- var req = https.request(options, function(res){
- res.on('data', function(d){
- d = d.toString();
- var index = d.indexOf(',"name":"TriHard"');
- var end = index - 1;
- while (d.charAt(--index) != ':') {}
- trihardCount = d.substr(index+1, end-index);
- req.destroy();
- });
- });
- req.end();
- req.on('error', function(e){
- console.error(e);
- });
- }
- function sendTriHards() {
- if (prevCount == trihardCount) {
- suffix += ".";
- } else {
- prevCount = trihardCount;
- suffix = "";
- }
- var msg = "";
- for (var i = 0; i < 33; i++) {
- msg += " TriHard";
- }
- msg += " Count: " + numberWithSpaces(trihardCount);
- for (var i = 33; i < num; i++) {
- msg += " TriHard";
- }
- totalNum += num;
- client.say('#ice_poseidon', msg);
- console.log("Sent TriHard x " + num + ". Total TriHards: " + numberWithSpaces(trihardCount) + suffix + ". Total TriHards by this bot: " + totalNum + ".");
- }
- function init() {
- var config = {
- channels: ['#ice_poseidon'],
- username: 'username here',
- password: 'passwordgoeshere (pref. oauth token)',
- floodProtection: false,
- floodProtectionDelay: 2500
- };
- console.log("Fetched irc module.");
- client = new irc.Client('irc.chat.twitch.tv', config.username, config);
- setInterval(updateTriHardCount, 2500);
- client.addListener('registered', function(message){
- console.log("Connected!");
- setInterval(sendTriHards, 2500);
- });
- }
- init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement