From 8154eb3663123472dc4366571d4867bd5715cde6 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 22 Jan 2018 23:45:03 +0000 Subject: [PATCH] Google Feud but with args --- commands/games/google-feud.js | 20 +++++++++++++------- package.json | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/commands/games/google-feud.js b/commands/games/google-feud.js index 9ac0e1bf..3c0311f9 100644 --- a/commands/games/google-feud.js +++ b/commands/games/google-feud.js @@ -9,18 +9,26 @@ module.exports = class GoogleFeudCommand extends Command { name: 'google-feud', group: 'games', memberName: 'google-feud', - description: 'Attempt to determine the top suggestions for a Google search.' + description: 'Attempt to determine the top suggestions for a Google search.', + args: [ + { + key: 'question', + prompt: 'What question do you want to use for the game?', + type: 'string', + default: () => questions[Math.floor(Math.random() * questions.length)] + } + ] }); this.playing = new Set(); } - async run(msg) { + async run(msg, { question }) { if (this.playing.has(msg.channel.id)) return msg.reply('Only one fight may be occurring per channel.'); this.playing.add(msg.channel.id); - const question = questions[Math.floor(Math.random() * questions.length)]; try { const suggestions = await this.fetchSuggestions(question); + if (!suggestions) return msg.say('Could not find any results.'); const display = new Array(suggestions.length).fill('???'); let tries = 3; while (display.includes('???') && tries) { @@ -64,10 +72,8 @@ module.exports = class GoogleFeudCommand extends Command { client: 'firefox', q: question }); - const suggestions = JSON.parse(text)[1]; + const suggestions = JSON.parse(text)[1].filter(suggestion => suggestion.toLowerCase() !== question.toLowerCase()); if (!suggestions.length) return null; - return suggestions - .filter(suggestion => suggestion.toLowerCase() !== question.toLowerCase()) - .map(suggestion => suggestion.toLowerCase().replace(question.toLowerCase(), '').trim()); + return suggestions.map(suggestion => suggestion.toLowerCase().replace(question.toLowerCase(), '').trim()); } }; diff --git a/package.json b/package.json index e2788888..9032e4f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "61.3.1", + "version": "61.4.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {