Google Feud Command

This commit is contained in:
Daniel Odendahl Jr
2017-12-14 15:33:47 +00:00
parent 03af278a4a
commit c33abe6390
4 changed files with 139 additions and 2 deletions
+66
View File
@@ -0,0 +1,66 @@
[
"Are cats",
"Are dogs",
"Are birds",
"Do cats",
"Do dogs",
"Do birds",
"Am I",
"Is Google",
"Is it bad to",
"Am I going to",
"What is the best way to",
"Am I going to",
"Can cats",
"Can I",
"Can you",
"Is it okay to",
"Will I die if",
"Does the world hate",
"Does everyone hate",
"Can you code",
"JavaScript is",
"Schools are",
"Is Discord",
"What is",
"Where is",
"Did dinosaurs",
"When will",
"When will Owl City",
"Is anime",
"What anime is",
"Am I part",
"Does Google know",
"Is the world",
"What game is",
"What game has",
"Is net neutrality",
"What is the worst",
"What is the best",
"Is Kingdom Hearts",
"Can Hobbits",
"Can humans",
"Is chocolate",
"Are cameras",
"Who is the most",
"Who is the least",
"Am I going to pass",
"Google is",
"Can you eat",
"Eat pant",
"Are computers",
"Is it legal to",
"Am I allowed to",
"Is it possible to",
"Can I have",
"Can Neopets",
"Can I go",
"Can you die from",
"Should I",
"Will I die",
"Am I",
"Do people hate",
"Do people love",
"Am I in",
"Am I going to"
]
+71
View File
@@ -0,0 +1,71 @@
const { Command } = require('discord.js-commando');
const snekfetch = require('snekfetch');
const { MessageEmbed } = require('discord.js');
const questions = require('../../assets/json/google-feud');
module.exports = class GoogleFeudCommand extends Command {
constructor(client) {
super(client, {
name: 'google-feud',
group: 'google-feud',
memberName: 'battle',
description: 'Attempt to determine the top suggestions for a Google search.'
});
this.playing = new Set();
}
async run(msg) {
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);
const display = new Array(suggestions.length).fill('???');
let fails = 0;
while (suggestions.length !== display.length && fails < 3) {
const embed = new MessageEmbed()
.setColor(0x005AF0)
.setTitle(`${question}...?`)
.setDescription('Type the choice you think is a suggestion _without_ the question.')
.setFooter(`${3 - fails} tries remaining!`);
for (let i = 0; i < suggestions.length; i++) embed.addField(` ${10000 - (i * 1000) || 500}`, display[i]);
embed.addBlankField();
await msg.embed(embed);
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
max: 1,
time: 30000
});
if (!msgs.size) {
await msg.say('Time is up!');
break;
}
const choice = msgs.first().content.toLowerCase();
if (suggestions.includes(choice)) {
await msg.say('Nice job!');
display[suggestions.indexOf(choice)] = choice;
} else {
++fails;
await msg.say(`Nope! ${3 - fails} tries remaining!`);
}
}
if (fails > 3) return msg.say('Better luck next time!');
return msg.say('You win! Nice job, master of Google!');
} catch (err) {
this.playing.delete(msg.channel.id);
throw err;
}
}
async fetchSuggestions(question) {
const { text } = await snekfetch
.get('https://suggestqueries.google.com/complete/search')
.query({
client: 'firefox',
q: question
});
const suggestions = JSON.parse(text)[1];
if (!suggestions.length) return null;
return suggestions.map(suggestion => suggestion.toLowerCase().replace(question.toLowerCase(), '').trim());
}
};
+1 -1
View File
@@ -26,7 +26,7 @@ module.exports = class HangmanCommand extends Command {
let points = 0;
const confirmation = [];
const incorrect = [];
const display = '_'.repeat(word.length).split('');
const display = new Array(word.length).fill('_');
while (word.length !== confirmation.length && points < 7) {
await msg.say(stripIndents`
\`${display.join(' ')}\`. Which letter do you choose?
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "58.0.0",
"version": "58.1.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {