[HQ] Auto WS logger

This commit is contained in:
vilP1L
2019-06-08 09:50:01 -04:00
parent 113f67babe
commit d86ca3316b
2 changed files with 18 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ Wilder Emu Bot + Trivia Emulator
- [ ] Confetti Support
- [ ] Working UI
- [ ] Add Auto Update (CircleCI)
- [ ] Auto WS Logger
- [X] Auto WS Logger
- [ ] WS Reconnecting
- [X] Checkpoint Support (HQ)
- [X] Auto Checkpoint Claiming

View File

@@ -1,15 +1,15 @@
/* eslint-disable no-useless-escape */
import { MessageEmbed, MessageAttachment } from 'discord.js';
import { promisify } from 'util';
import request from 'request';
import Client from '../classes/Client';
import {
discord,
emuOnly,
hq,
} from '../../config';
import { discord, emuOnly, hq } from '../../config';
import { getTokens } from '../utils/tokens';
import search from '../utils/google';
import genResults from '../utils/img';
request.promise = promisify(request);
export default async (client, prize) => {
const tokens = getTokens(discord.defaultTokenSet);
// eslint-disable-next-line max-len
@@ -31,8 +31,10 @@ export default async (client, prize) => {
let questionNumber;
let winners;
let winnings;
const wsLog = [];
master.ws.on('message', async (data) => {
const json = JSON.parse(data);
wsLog.push(data);
if (json.type === 'question') {
client.weights.hq = [0, 0, 0];
client.userAnswers.hq = [];
@@ -172,12 +174,21 @@ export default async (client, prize) => {
});
master.ws.on('close', async () => {
if (!emuOnly) channels.forEach(c => c.send('**GAME OVER!**'));
const image = genResults('HQ Trivia', winners, winnings, `${correctCount}/${questionCount}`);
const image = genResults('HQ Trivia', winners || 0, winnings || 0, `${correctCount}/${questionCount || 0}`);
const attachment = new MessageAttachment(image);
if (!emuOnly) channels.forEach(c => c.send(attachment));
if (discord.logs) client.channels.get(discord.logChannel).send(attachment);
client.activeGames.splice(client.activeGames.indexOf('hq-trivia'), 1);
client.hqClients = [];
const { body } = await request.promise('https://pastebin.com/api/api_post.php?', {
method: 'POST',
form: {
api_option: 'paste',
api_dev_key: 'b7ac578d7d735606fde6339131885f38',
api_paste_code: wsLog.join('\n'),
},
});
if (!emuOnly) channels.forEach(c => c.send(`WebSocket Log: ${body}`));
});
tokens.forEach(async (t, i) => {
const hq = new Client(t, i + 1);