Google Feud but with args

This commit is contained in:
Daniel Odendahl Jr
2018-01-22 23:45:03 +00:00
parent ac8fb400df
commit 8154eb3663
2 changed files with 14 additions and 8 deletions
+13 -7
View File
@@ -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());
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "61.3.1",
"version": "61.4.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {