66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
import request from 'request';
|
|
import { accounts } from './accounts.json';
|
|
import { HEADERS, SERVER_URL } from './config';
|
|
|
|
export default class Summary {
|
|
constructor() {
|
|
this.logger = null;
|
|
this.totalBalance = parseFloat("0.00");
|
|
this.totalCash = parseFloat("0.00");
|
|
this.playersReturned = 0;
|
|
}
|
|
|
|
async run() {
|
|
console.log(`You have ${accounts.length} players available!\n`);
|
|
console.log(`Player\t\tBalance\t Total\t Lives\t Wins\tGames Played\t% Won`);
|
|
accounts.forEach(this.getPlayerSummary.bind(this));
|
|
|
|
const getSummary = setInterval(() => {
|
|
if (this.playersReturned === accounts.length) {
|
|
console.log(`\nTotal Available Cash: $${this.totalBalance.toFixed(2)}`);
|
|
console.log(`Total Cash Won Historically: $${this.totalCash.toFixed(2)}`);
|
|
clearInterval(getSummary);
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
getPlayerSummary(player) {
|
|
const { username } = player;
|
|
|
|
request({
|
|
url: `https://${SERVER_URL}/users/me`,
|
|
headers: {
|
|
...HEADERS,
|
|
authorization: `Bearer ${player.accessToken}`,
|
|
}
|
|
}, (error, response, body) => {
|
|
this.playersReturned++;
|
|
try {
|
|
const result = JSON.parse(body);
|
|
const { lives, leaderboard } = result;
|
|
const { total, unclaimed: balance } = leaderboard;
|
|
|
|
let gamesPlayed = 0;
|
|
let winCount = 0;
|
|
let winRatio = 0;
|
|
|
|
this.totalBalance += parseFloat(balance.replace('$',''));
|
|
this.totalCash += parseFloat(total.replace('$',''));
|
|
|
|
if (result.gamesPlayed) {
|
|
gamesPlayed = result.gamesPlayed;
|
|
winCount = result.winCount;
|
|
|
|
winRatio = Math.round(winCount / gamesPlayed * 100);
|
|
}
|
|
|
|
const extraT = username.length < 8 ? '\t' : '';
|
|
|
|
console.log(`${username}${extraT}\t${balance}\t ${total}\t ${lives} Lives ${winCount} Wins\t${gamesPlayed}\t\t${winRatio}%`);
|
|
} catch (error) {
|
|
console.log('Error\n', error.toString('utf8'));
|
|
}
|
|
});
|
|
}
|
|
}
|