[HQ, Config] Make checking balances much faster, config changes, and minor embed changes

This commit is contained in:
vilP1L
2019-08-16 14:39:50 -04:00
parent 4a704bd768
commit d166ce1fda
4 changed files with 54 additions and 38 deletions

View File

@@ -96,8 +96,9 @@
"autoSplitOnLastQuestion": false, "autoSplitOnLastQuestion": false,
"autoLife": true, "autoLife": true,
"autoLifeQuestionThreshold": 9, "autoLifeQuestionThreshold": 9,
"splitThreshold": 0.65, "splitThreshold": 0.6,
"autoCheckpoints": true, "autoCheckpoints": true,
"checkpointThreshold": 0.40 "checkpointThreshold": 0.40,
"maxLivesPerGame": 2
} }
} }

View File

@@ -132,13 +132,17 @@ client.on('message', async (msg) => {
const index = numberEmojis.indexOf(collected.array()[0].emoji.name); const index = numberEmojis.indexOf(collected.array()[0].emoji.name);
const tokens = getTokens(tokenFiles[index]); const tokens = getTokens(tokenFiles[index]);
const message = await msg.channel.send(`Checking ${tokens.length} tokens...`); const message = await msg.channel.send(`Checking ${tokens.length} tokens...`);
let i = 1; const startTime = Date.now();
let unlockedBalance = 0; let unlockedBalance = 0;
let unlockedAccounts = 0; let unlockedAccounts = 0;
let lockedBalance = 0; let lockedBalance = 0;
let lockedAccounts = 0; let lockedAccounts = 0;
let noBalance = 0; let noBalance = 0;
let i = 1;
const tasks = [];
for (const token of tokens) { for (const token of tokens) {
// eslint-disable-next-line no-loop-func
const promise = async () => {
const hq = new HQClient(token, i); const hq = new HQClient(token, i);
await hq.login(); await hq.login();
const { balance, eligibleForPayout } = await hq.getBalance(); const { balance, eligibleForPayout } = await hq.getBalance();
@@ -154,8 +158,12 @@ client.on('message', async (msg) => {
} }
if (balance === 0) noBalance += 1; if (balance === 0) noBalance += 1;
i += 1; i += 1;
return balance;
};
tasks.push(promise());
} }
message.edit('Finished Checking Accounts!'); await Promise.all(tasks);
message.edit(`Finished Checking ${tokens.length} Accounts in ${(Date.now() - startTime) / 1000}s!`);
const embed = new MessageEmbed() const embed = new MessageEmbed()
.setTitle('Balance') .setTitle('Balance')
.addField('Unlocked Balance', `$${unlockedBalance.toFixed(2)} across ${unlockedAccounts} accounts`) .addField('Unlocked Balance', `$${unlockedBalance.toFixed(2)} across ${unlockedAccounts} accounts`)

View File

@@ -15,7 +15,12 @@ export default async () => {
let livesCount = 0; let livesCount = 0;
let erasersCount = 0; let erasersCount = 0;
let index = 0; let index = 0;
const tasks = [];
const startTime = Date.now();
console.edit(`Checking ${tokens.length} accounts...`.yellow);
for (const token of tokens) { for (const token of tokens) {
// eslint-disable-next-line no-loop-func
const promise = async () => {
index += 1; index += 1;
const client = new Client(token, index - 1); const client = new Client(token, index - 1);
await client.login(); await client.login();
@@ -32,9 +37,11 @@ export default async () => {
lockedCount += 1; lockedCount += 1;
lockedBalance += balance; lockedBalance += balance;
} }
console.edit(`Checked ${index}/${tokens.length} accounts.`.yellow); };
tasks.push(promise());
} }
console.edit(`Finished checking ${tokens.length} accounts!`.green, true); await Promise.all(tasks);
console.edit(`Finished checking ${tokens.length} accounts in ${(Date.now() - startTime) / 1000}s!`.green, true);
if (unlockedCount) console.log(`${' Unlocked Balance '.bgGreen.black} $${unlockedBalance.toFixed(2)} across ${unlockedCount} accounts`); if (unlockedCount) console.log(`${' Unlocked Balance '.bgGreen.black} $${unlockedBalance.toFixed(2)} across ${unlockedCount} accounts`);
if (lockedCount) console.log(`${' Locked Balance '.bgRed.black} $${lockedBalance.toFixed(2)} across ${lockedCount} accounts`); if (lockedCount) console.log(`${' Locked Balance '.bgRed.black} $${lockedBalance.toFixed(2)} across ${lockedCount} accounts`);
if (noBalanceCount) console.log(`${' No Balance '.bgYellow.black} ${noBalanceCount}`); if (noBalanceCount) console.log(`${' No Balance '.bgYellow.black} ${noBalanceCount}`);

View File

@@ -159,7 +159,7 @@ export default async (client, prize) => {
}); });
master.ws.on('close', async () => { master.ws.on('close', async () => {
if (!emuOnly) channels.forEach(c => c.send('**GAME OVER!**')); if (!emuOnly) channels.forEach(c => c.send('**GAME OVER!**'));
const image = genResults('HQ Trivia', winners || 0, winnings || 0, `${correctCount}/${master.questionCount || 0}`); const image = genResults('HQ Trivia', winners || 0, winnings || 0, `${correctCount}/${master.questionNumber || 0}`);
const attachment = new MessageAttachment(image); const attachment = new MessageAttachment(image);
if (!emuOnly) channels.forEach(c => c.send(attachment)); if (!emuOnly) channels.forEach(c => c.send(attachment));
if (discord.logs) client.channels.get(discord.logChannel).send(attachment); if (discord.logs) client.channels.get(discord.logChannel).send(attachment);