Wordnik in Hangman

This commit is contained in:
Daniel Odendahl Jr
2017-06-14 02:15:29 +00:00
parent 5a0df98b9a
commit c0b344c287
2 changed files with 15 additions and 19 deletions
-17
View File
@@ -1,17 +0,0 @@
[
"hangman",
"cats",
"kirby",
"xiaobot",
"daniel",
"pants",
"portal",
"foster",
"pancake",
"pens",
"computer",
"xiao",
"mouse",
"pikachu",
"nonsense"
]
+15 -2
View File
@@ -1,6 +1,7 @@
const Command = require('../../structures/Command');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const words = require('../../assets/json/hangman');
const { WORDNIK_KEY } = process.env;
module.exports = class HangmanCommand extends Command {
constructor(client) {
@@ -18,7 +19,19 @@ module.exports = class HangmanCommand extends Command {
async run(msg) {
if (this.playing.has(msg.guild.id)) return msg.say('Only one game may be occurring per server.');
this.playing.add(msg.guild.id);
const word = words[Math.floor(Math.random() * words.length)];
const { body } = await snekfetch
.get('http://api.wordnik.com:80/v4/words.json/randomWord')
.query({
hasDictionaryDef: true,
minCorpusCount: 0,
maxCorpusCount: -1,
minDictionaryCount: 1,
maxDictionaryCount: -1,
minLength: -1,
maxLength: -1,
api_key: WORDNIK_KEY
});
const { word } = body;
let points = 0;
const confirmation = [];
const display = '_'.repeat(word.length).split('');