Add Cashout; Update Client Strings; Prettify account summary
This commit is contained in:
+37
-9
@@ -8,7 +8,7 @@ import Account from './classes/Account';
|
||||
const HOST = 'api-quiz.hype.space';
|
||||
const INIT_TOKEN = mainBearerToken;
|
||||
const headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
'x-hq-client': 'Android/1.12.2',
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
'user-agent': 'okhttp/3.8.0',
|
||||
};
|
||||
@@ -23,15 +23,43 @@ players.forEach((player) => {
|
||||
authorization: `Bearer ${player.accessToken}`,
|
||||
}
|
||||
}, (error, response, body) => {
|
||||
const result = JSON.parse(body);
|
||||
console.log(`\nPlayer ${player.username}:`);
|
||||
if (result.gamesPlayed) {
|
||||
console.log(`\tGames Played: ${result.gamesPlayed}`);
|
||||
console.log(`\tGames Won: ${result.winCount}`);
|
||||
console.log(`\tWin Percentage: ${Math.round(result.winCount / result.gamesPlayed)}%`);
|
||||
console.log('\t===================================');
|
||||
try {
|
||||
const result = JSON.parse(body);
|
||||
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, ` Games Played: ${gamesPlayed}`);
|
||||
console.log(formatString, ` Games Won: ${winCount}`);
|
||||
console.log(formatString, ` Win Percentage: ${winRatio}%`);
|
||||
|
||||
const balance = result.leaderboard.unclaimed;
|
||||
const { total } = result.leaderboard;
|
||||
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'));
|
||||
}
|
||||
console.log(`\tAccount Balance: ${result.leaderboard.unclaimed}`);
|
||||
}
|
||||
);
|
||||
});
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { players } from './config.json';
|
||||
import Account from './classes/Account';
|
||||
|
||||
const CASH_OUT_PLAYER = 'wiseaegg1';
|
||||
const REAL_PAYPAL = 'slim.adad1937@gmail.com';
|
||||
|
||||
const player = players.find((player) => player.username === CASH_OUT_PLAYER);
|
||||
|
||||
console.log(`Cashing out ${player.username}!`);
|
||||
const playerAccount = new Account(player);
|
||||
playerAccount.cashout(REAL_PAYPAL);
|
||||
+28
-1
@@ -7,7 +7,7 @@ import { parseString } from 'xml2js';
|
||||
|
||||
const HOST = 'api-quiz.hype.space';
|
||||
const headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
'x-hq-client': 'Android/1.12.2',
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
'user-agent': 'okhttp/3.8.0',
|
||||
};
|
||||
@@ -59,6 +59,33 @@ export default class Account {
|
||||
}
|
||||
}
|
||||
|
||||
cashout(email) {
|
||||
const options = {
|
||||
host: HOST,
|
||||
path: '/users/me/payouts',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...headers,
|
||||
'authorization': `Bearer ${this.accessToken}`,
|
||||
},
|
||||
};
|
||||
|
||||
const req = https.request(options, (res, err) => {
|
||||
if (err) {
|
||||
console.log(`Error occurred cashing out for ${this.username} with email ${email}:`, err);
|
||||
return;
|
||||
}
|
||||
console.log('Sent request successfully? Waiting for data.')
|
||||
|
||||
res.on('data', (data) => {
|
||||
console.log('RESULT', data.toString('utf8'));
|
||||
});
|
||||
});
|
||||
|
||||
req.write(JSON.stringify({email}));
|
||||
req.end();
|
||||
};
|
||||
|
||||
changeAvatar() {
|
||||
let awsCredentials;
|
||||
let error;
|
||||
|
||||
@@ -3,7 +3,7 @@ import Account from './Account';
|
||||
|
||||
const HOST = 'api-quiz.hype.space';
|
||||
const headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
'x-hq-client': 'Android/1.12.2',
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
'user-agent': 'okhttp/3.8.0',
|
||||
};
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import Verification from './classes/Verification';
|
||||
const HOST = 'api-quiz.hype.space';
|
||||
const INIT_TOKEN = mainBearerToken;
|
||||
const headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
'x-hq-client': 'Android/1.12.2',
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
'user-agent': 'okhttp/3.8.0',
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import Account from './classes/Account';
|
||||
const HOST = 'api-quiz.hype.space';
|
||||
const INIT_TOKEN = mainBearerToken;
|
||||
const headers = {
|
||||
'x-hq-client': 'Android/1.6.2',
|
||||
'x-hq-client': 'Android/1.12.2',
|
||||
'content-type': 'application/json; charset=UTF-8',
|
||||
'user-agent': 'okhttp/3.8.0',
|
||||
};
|
||||
@@ -127,7 +127,8 @@ request('https://api-quiz.hype.space/shows/now', (error, response, body) => {
|
||||
}
|
||||
});
|
||||
|
||||
console.log('\x1b[1m\x1b[32m%s\x1b[0m', `\nAnswer was ${index + 1}: ${correctAnswer.text}`);
|
||||
const answerText = correctAnswer.text || correctAnswer.answer || 'undefined';
|
||||
console.log('\x1b[1m\x1b[32m%s\x1b[0m', `\nAnswer was ${index + 1}: ${answerText}`);
|
||||
|
||||
if (wrongPlayers.length > 0) {
|
||||
console.log('\x1b[1m\x1b[31m%s\x1b[0m', `${wrongPlayers.length} players have been eliminated!`);
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@
|
||||
"start": "babel-node hqnode.js --presets env,es2016,stage-2",
|
||||
"create": "babel-node createAccount.js --presets env,es2016,stage-2",
|
||||
"summary": "babel-node accountSummary.js --presets env,es2016,stage-2",
|
||||
"avatar": "babel-node changeAvatar.js --presets env,es2016,stage-2"
|
||||
"avatar": "babel-node changeAvatar.js --presets env,es2016,stage-2",
|
||||
"cashout": "babel-node cashout.js --presets env,es2016,stage-2"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
|
||||
Reference in New Issue
Block a user