84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
import prompt from 'prompt';
|
|
import request from 'request';
|
|
import WebSocket from 'ws';
|
|
|
|
import { mainBearerToken, players } from './config.json';
|
|
import Account from './classes/Account';
|
|
|
|
const HOST = 'api-quiz.hype.space';
|
|
const INIT_TOKEN = mainBearerToken;
|
|
const headers = {
|
|
'x-hq-client': 'Android/1.12.2',
|
|
'content-type': 'application/json; charset=UTF-8',
|
|
'user-agent': 'okhttp/3.8.0',
|
|
};
|
|
|
|
|
|
let playersReturned = 0;
|
|
let totalBalance = parseFloat("0.00");
|
|
let totalCash = parseFloat("0.00");
|
|
|
|
console.log(`You have ${players.length} players available!`);
|
|
|
|
players.forEach((player) => {
|
|
request({
|
|
url: 'https://api-quiz.hype.space/users/me',
|
|
headers: {
|
|
...headers,
|
|
authorization: `Bearer ${player.accessToken}`,
|
|
}
|
|
}, (error, response, body) => {
|
|
playersReturned++;
|
|
try {
|
|
const result = JSON.parse(body);
|
|
const { lives } = result;
|
|
let gamesPlayed = 0;
|
|
let winCount = 0;
|
|
let winRatio = 0;
|
|
let formatString = '%s';
|
|
|
|
if (result.gamesPlayed) {
|
|
gamesPlayed = result.gamesPlayed;
|
|
winCount = result.winCount;
|
|
|
|
winRatio = Math.round(winCount / gamesPlayed * 100);
|
|
const getColor = (winRatio) => {
|
|
if (winRatio === 0) return '37'; // white
|
|
if (winRatio < 33) return '33'; // yellow
|
|
if (winRatio < 66) return '36'; // cyan
|
|
return '32'; // green
|
|
};
|
|
formatString = `\x1b[1m\x1b[${getColor(winRatio)}m%s\x1b[0m`;
|
|
}
|
|
|
|
console.log(formatString, `\n\nPlayer ${player.username}:`);
|
|
console.log(formatString, '===================================');
|
|
|
|
console.log(formatString, ` ${winRatio}% Won (${gamesPlayed} played with ${winCount} wins)`);
|
|
console.log(formatString, ` ${lives} lives remaining!`);
|
|
|
|
const balance = result.leaderboard.unclaimed;
|
|
const { total } = result.leaderboard;
|
|
|
|
totalBalance += parseFloat(balance.replace('$',''));
|
|
totalCash += parseFloat(total.replace('$',''));
|
|
|
|
const accountBalanceString = balance === '$0' ? formatString : '\x1b[1m\x1b[32m%s\x1b[0m';
|
|
console.log(accountBalanceString, ` Account Balance: ${balance}`);
|
|
console.log(formatString, ` Total Cash Won: ${total}`);
|
|
console.log(formatString, '===================================');
|
|
} catch (error) {
|
|
console.log('Error\n', body.toString('utf8'));
|
|
}
|
|
}
|
|
);
|
|
});
|
|
|
|
const getSummary = setInterval(() => {
|
|
if (playersReturned === players.length) {
|
|
console.log(`\nTotal Available Cash: $${totalBalance.toFixed(2)}`);
|
|
console.log(`\nTotal Cash Won Historically: $${totalCash.toFixed(2)}`);
|
|
clearInterval(getSummary);
|
|
}
|
|
}, 1000);
|