Initial Commit

This commit is contained in:
vilP1L
2019-05-13 20:33:24 -04:00
commit 49e097a6b1
12 changed files with 3921 additions and 0 deletions

51
src/modules/hq-cashout.js Normal file
View File

@@ -0,0 +1,51 @@
import { prompt } from 'enquirer';
import Client from '../classes/Client';
import select from '../utils/selectTokens';
import { catchall } from '../../config';
console.edit = (string, end) => process.stdout.clearLine() || process.stdout.write(`\r${string}${end ? '\n' : ''}`);
export default async () => {
const tokens = await select();
const clients = [];
let unlockedCount = 0;
let unlockedBalance = 0;
let lockedCount = 0;
let lockedBalance = 0;
let noBalanceCount = 0;
let index = 0;
for (const token of tokens) {
index += 1;
const client = new Client(token.loginToken, index - 1);
await client.login();
clients.push(client);
const { balance, eligibleForPayout } = await client.getBalance();
if (balance === 0) noBalanceCount += 1;
if (eligibleForPayout) {
unlockedCount += 1;
unlockedBalance += balance;
} else {
lockedCount += 1;
lockedBalance += balance;
}
console.edit(`Checked ${index}/${tokens.length} accounts.`.yellow);
}
console.edit(`Finished checking ${tokens.length} accounts!`.green, true);
console.log(`${' Unlocked Balance '.bgGreen.black} $${unlockedBalance.toFixed(2)}`);
console.log(`${' Unlocked Accounts '.bgGreen.black} ${unlockedCount}`);
console.log(`${' Locked Balance '.bgRed.black} $${lockedBalance.toFixed(2)}`);
console.log(`${' Locked Accounts '.bgRed.black} ${lockedCount}`);
console.log(`${' No Balance '.bgYellow.black} ${noBalanceCount}`);
const { num } = await prompt({
type: 'numeral',
name: 'num',
message: 'How many accounts would you like to cashout?',
});
const accounts = clients.filter(c => c.canCashout);
if (num > accounts.length) return console.log(`Only ${accounts.length} account(s) are able to cashout.`.red);
for (let i = 0; i < num; i += 1) {
await accounts[i].cashout(catchall);
}
console.log(`Finished cashing out ${num} account(s)!`.green);
return true;
};

View File

44
src/modules/hq.js Normal file
View File

@@ -0,0 +1,44 @@
import { prompt } from 'enquirer';
import Client from '../classes/Client';
import select from '../utils/selectTokens';
export default async () => {
const tokens = await select();
const { numClients } = await prompt({
type: 'numeral',
name: 'numClients',
message: 'How many clients would you like to use?',
});
const { useTestWs } = await prompt({
type: 'confirm',
name: 'useTestWs',
message: 'Would you like to use the test WebSocket?',
});
const master = new Client(tokens[0].loginToken, 0);
const clients = [];
master.testWs = useTestWs;
tokens.shift();
await master.login();
await master.connect();
master.ws.on('message', async (msg) => {
const { type, answers } = JSON.parse(msg);
if (type === 'question') {
const { choice } = await prompt({
type: 'select',
name: 'choice',
message: 'Please choose an option',
choices: [`1 - ${answers[0].text}`, `2 - ${answers[1].text}`, `3 - ${answers[2].text}`],
});
const num = Number(choice.match(/[1-9]/)[0]);
master.submitAnswer(num - 1);
clients.forEach(c => c.submitAnswer(num - 1));
}
});
for (let i = 0; i < numClients; i += 1) {
const client = new Client(tokens[i].loginToken, i + 1);
await client.login();
client.testWs = useTestWs;
await client.connect();
clients.push(client);
}
};