Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const request = require('async-request');
- const moment = require('moment');
- const tmi = require('tmi.js');
- //const token = 'oauth:5bugc3awqv8t2t5kw2sdwze4f3ly54'
- //const username = 'expectedbot64'
- //const channel = 'expectedint64'
- const options = {
- options: {
- debug: true,
- },
- connection: {
- cluster: 'aws',
- reconnect: true,
- },
- identity: {
- username: 'expectedbot64',
- password: 'oauth:5bugc3awqv8t2t5kw2sdwze4f3ly54',
- },
- channels: ['expectedint64'],
- };
- const client = new tmi.client(options);
- function playerBet(name, min, sec) {
- this.userName = name;
- this.guessMin = min;
- this.guessSec = sec;
- };
- var playerBets = [];
- client.connect();
- client.on('connected', (address, port) => {
- client.action('expectedint64', 'Guess bot is now active, guess when the first death is using: !fd xx:xx');
- });
- const initialTime = Date.now();
- let lastRequest = initialTime;
- async function pull() {
- const startTime = lastRequest - initialTime;
- const currentTime = Date.now();
- const endTime = currentTime - initialTime;
- lastRequest = currentTime;
- const code = "jg7MaLWQNxfmPZ34";
- const api_key = "03ab0b4c402ab1296768abc6737133f4";
- const response = await request(`https://www.warcraftlogs.com/v1/report/tables/deaths/${code}?end=${endTime}&api_key=${api_key}&start=${startTime}`);
- const json = JSON.parse(response.body);
- if (json.entries.length === 0) {
- console.log("No one died :(");
- } else {
- console.log(
- json.entries
- .map(entry => entry.name + " died at " + moment(initialTime + entry.timestamp).format("dddd, MMMM Do YYYY, h:mm:ss a"))
- .join("\n")
- );
- }
- setTimeout(pull, 10000);
- }
- //pull(); // uncomment for live death feedback
- //Get fights
- const allFights = [];
- async function getNewFights() {
- //rJ9AxNF6VqcnzCHX
- //2FD6G3QA1j9cHB8n
- const code = "TnmqJrx8CZ6pvaW7";
- const api_key = "03ab0b4c402ab1296768abc6737133f4";
- const response = await request(`https://www.warcraftlogs.com/v1/report/fights/${code}?&api_key=${api_key}`);
- const json = JSON.parse(response.body);
- const fights = json.fights;
- const newFights = fights.slice(allFights.length);
- allFights.push(...newFights);
- return newFights;
- }
- //Get 1st death and print
- async function getDeaths() {
- const newFights = await getNewFights();
- if (newFights.length === 0) {
- console.log("No new fights");
- //setTimeout(getDeaths, 50000);
- }
- else {
- const startTime = newFights.reduce((time, fight) => Math.min(fight.start_time, time), newFights[0].start_time);
- const endTime = newFights.reduce((time, fight) => Math.max(fight.end_time, time), newFights[0].end_time);
- //rJ9AxNF6VqcnzCHX
- //2FD6G3QA1j9cHB8n
- const code = "TnmqJrx8CZ6pvaW7";
- const api_key = "03ab0b4c402ab1296768abc6737133f4";
- const response = await request(`https://www.warcraftlogs.com/v1/report/tables/deaths/${code}?end=${endTime}&api_key=${api_key}&start=${startTime}`);
- const json = JSON.parse(response.body);
- if (json.entries.length === 0) {
- console.log("No one died :(");
- client.action('expectedint64', 'No one died, guess again!');
- playerBets = [];
- } else {
- //const deathTime = Math.floor(((entry.timestamp - newFights[0].start_time)/1000));
- //var deathMinutes = Math.floor(Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) / 60);
- // var deathSeconds = Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) - Math.floor(Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) / 60) * 60;
- if (json.entries.length > 0) {
- const entry = json.entries[0];
- const deathTimeMinutes = Math.floor(Math.floor(((entry.timestamp - newFights[0].start_time) / 1000)) / 60);
- const deathTimeSeconds = Math.floor(((entry.timestamp - newFights[0].start_time) / 1000)) - deathTimeMinutes * 60;
- const killer = entry.killingBlow ? entry.killingBlow.name : "unknown";
- client.action('expectedint64', entry.name + " died at: " + deathTimeMinutes + " minutes and " + deathTimeSeconds + " seconds, fighting: " + newFights[0].name + ", from: " + killer + "! What a pleb :)");
- for(i = 0; i<playerBets.length; i++)
- {
- console.log(playerBets[i].guessMin + '=' + deathTimeMinutes + '|' +playerBets[i].guessSec + '='+deathTimeSeconds + typeof(deathTimeMinutes) + typeof(playerBets[i].guessMin));
- if(parseInt(playerBets[i].guessMin, 10) === parseInt(deathTimeMinutes, 10) && parseInt(playerBets[i].guessSec, 10) === parseInt(deathTimeSeconds, 10))
- {
- console.log("True");
- client.action('expectedint64', playerBets[i].userName + ' guessed the first death!');
- }
- }
- playerBets = [];
- }
- /*client.action('expectedint64', json.entries
- .map(entry => entry.name + " died at: " + (Math.floor(Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) / 60)) + " minutes and "+ (Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) - Math.floor(Math.floor(((entry.timestamp - newFights[0].start_time)/1000)) / 60) * 60) + " seconds, fighting: " + newFights[0].name + ", from: " + (entry.killingBlow ? entry.killingBlow.name : "unknown") + " what a pleb")
- .join("\n"));*/
- /* console.log(
- json.entries
- .map(entry => entry.name + " died from: " + (entry.killingBlow ? entry.killingBlow.name : "unknown") + " at " + moment(initialTime + entry.timestamp).format("dddd, MMMM Do YYYY, h:mm:ss a"))
- .join("\n")
- );*/
- //console.log(json.entry.name);
- }
- }
- setTimeout(getDeaths, 60000);
- }
- getDeaths();
- //Betting in Chat
- client.on('chat', (channel, user, message, self) => {
- if (message.includes("!fd") && message.charAt(0) === '!') {
- var timeChatMin = 0;
- var timeChatSec = 0;
- var minDone = false;
- var firstPassMin = false;
- var firstPassSec = false;
- var timeDone = false;
- //var firstTimeDone = false;
- //var betAmount = 0;
- for (i = 0; i < message.length; i++) {
- console.log(message.charAt(i));
- //if (message.charAt(i) === " ") { timeDone = true; }
- /*f (!isNaN(message.charAt(i)) && timeDone) {
- if (!firstTimeDone) {
- betAmount = message.charAt(i);
- firstTimeDone = true;
- }
- else {
- betAmount = betAmount + message.charAt(i);
- }
- console.log('Bet has passed' + message.charAt(i));
- }*/
- if (message.charAt(i) === ':') { minDone = true; }
- if (!isNaN(message.charAt(i)) && !minDone) {
- if (!firstPassMin) {
- timeChatMin = message.charAt(i);
- firstPassMin = true;
- }
- else {
- timeChatMin = timeChatMin + message.charAt(i);
- }
- }
- if (!isNaN(message.charAt(i)) && minDone) {
- if (!firstPassSec) {
- timeChatSec = message.charAt(i);
- firstPassSec = true;
- }
- else {
- timeChatSec = timeChatSec + message.charAt(i);
- }
- }
- }
- playerBets.push(new playerBet(`${user['display-name']}`, timeChatMin, timeChatSec));
- client.action('expectedint64', `${user['display-name']}` + ' Thinks first death is at: ' + timeChatMin + ':' + timeChatSec);
- }
- if (message.includes('!done')) {
- for (i = 0; i < playerBets.length; i++) {
- console.log(playerBets[i].userName + ' guessed first death at: ' + playerBets[i].guessMin + ':' + playerBets[i].guessSec);
- }
- playerBets = [];
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement