Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var https = require('https');
- var irc = require('irc');
- if (!Date.now) {
- Date.now = function() { return new Date().getTime(); }
- }
- var startTime;
- var num = 69;
- var totalNum = 0;
- var suffix = ".";
- var trihardCount = "0";
- var dispCount = false;
- var client;
- var prevCount = trihardCount;
- var intervalId = null;
- var updateCountIntervalId = null;
- var bannedCheck = 0;
- var bannedTime;
- 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 += ".";
- if (suffix == "....") {
- suffix = ".";
- }
- } else {
- prevCount = trihardCount;
- suffix = ".";
- }
- var msg = "";
- for (var i = 0; i < 33; i++)
- msg += " TriHard";
- msg = "TriHard Count: " + numberWithSpaces(trihardCount);
- for (var i = 0; i < num; i++)
- msg += " TriHard";
- totalNum += num;
- var seconds = (Date.now() - startTime) / 1000;
- var time = "";
- var weeks = Math.floor(seconds / 604800);
- seconds = seconds - weeks * 604800;
- var days = Math.floor(seconds / 86400);
- seconds = seconds - days * 86400;
- var hours = Math.floor(seconds / 3600);
- seconds = seconds - hours * 3600;
- var minutes = Math.floor(seconds / 60);
- seconds = seconds - minutes * 60;
- if (weeks > 0) {
- time += weeks + "w ";
- }
- if (days > 0) {
- time += days + "d ";
- }
- if (hours > 0) {
- time += hours + "h ";
- }
- if (minutes > 0) {
- time += minutes + "m ";
- }
- if (seconds > 0) {
- time += parseFloat(seconds).toFixed(3) + "s";
- }
- client.say('#ice_poseidon', msg + suffix);
- console.log("Posted " + num + " TriHards. Total TriHards: " + numberWithSpaces(trihardCount) + ". Total TriHards by this bot: " + totalNum + ".\tUptime: " + time + ".");
- }
- function init() {
- var config = {
- channels: ['#ice_poseidon'],
- username: '',
- password: '',
- floodProtection: false,
- floodProtectionDelay: 2000
- };
- console.log("Fetched irc module.");
- client = new irc.Client('irc.chat.twitch.tv', config.username, config);
- updateCountIntervalId = setInterval(updateTriHardCount, 2000);
- client.addListener('registered', function(message){
- if (intervalId == null) {
- updateTriHardCount();
- startTime = Date.now();
- intervalId = setInterval(sendTriHards, 2200);
- } else {
- if (bannedCheck == 0)
- bannedTime = Date.now();
- if (Date.now() - bannedTime > 60000)
- bannedCheck = 0;
- bannedCheck++;
- if (bannedCheck == 5) {
- clearInterval(intervalId);
- clearInterval(updateCountIntervalId);
- client.disconnect();
- console.log("Probably banned...");
- }
- }
- });
- }
- init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement