From d86ca3316b27005be8f83fe16dd3b1637fa1b049 Mon Sep 17 00:00:00 2001 From: vilP1L Date: Sat, 8 Jun 2019 09:50:01 -0400 Subject: [PATCH] [HQ] Auto WS logger --- README.md | 2 +- src/modules/hq-discord.js | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cd8fd54..f979f7c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/modules/hq-discord.js b/src/modules/hq-discord.js index d9d4fa2..f750a02 100644 --- a/src/modules/hq-discord.js +++ b/src/modules/hq-discord.js @@ -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);