From 5524cfadd6cacc518935925463406d56071acc47 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Thu, 15 Jun 2017 03:15:21 +0000 Subject: [PATCH] setgetgo instead of wordnik --- commands/games/hangman.js | 100 ++++++++++++++++++-------------------- package.json | 2 +- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/commands/games/hangman.js b/commands/games/hangman.js index 114a2789..a6ccd55f 100644 --- a/commands/games/hangman.js +++ b/commands/games/hangman.js @@ -1,7 +1,6 @@ const Command = require('../../structures/Command'); const snekfetch = require('snekfetch'); const { stripIndents } = require('common-tags'); -const { WORDNIK_KEY } = process.env; module.exports = class HangmanCommand extends Command { constructor(client) { @@ -19,60 +18,55 @@ 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 { 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.word.toLowerCase().replace(/[ ]/g, '-'); - let points = 0; - const confirmation = []; - const incorrect = []; - const display = '_'.repeat(word.length).split(''); - while (word.length !== confirmation.length && points < 7) { - await msg.code(null, stripIndents` - ___________ - | | - | ${points > 0 ? 'O' : ''} - | ${points > 2 ? '—' : ' '}${points > 1 ? '|' : ''}${points > 3 ? '—' : ''} - | ${points > 4 ? '/' : ''} ${points > 5 ? '\\' : ''} - =========== - The word is: ${display.join(' ')}. Which letter do you choose? - `); - const guess = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, { - max: 1, - time: 30000 - }); - if (!guess.size) { - await msg.say('Time!'); - break; - } - const choice = guess.first().content.toLowerCase(); - if (confirmation.includes(choice) || incorrect.includes(choice)) { - await msg.say('You have already picked that letter!'); - } else if (word.includes(choice)) { - await msg.say('Nice job!'); - for (let i = 0; i < word.length; i++) { - if (word[i] === choice) { - confirmation.push(word[i]); - display[i] = word[i]; - } + try { + const { text } = await snekfetch + .get('http://setgetgo.com/randomword/get.php'); + const word = text.toLowerCase().replace(/[ ]/g, '-'); + let points = 0; + const confirmation = []; + const incorrect = []; + const display = '_'.repeat(word.length).split(''); + while (word.length !== confirmation.length && points < 7) { + await msg.code(null, stripIndents` + ___________ + | | + | ${points > 0 ? 'O' : ''} + | ${points > 2 ? '—' : ' '}${points > 1 ? '|' : ''}${points > 3 ? '—' : ''} + | ${points > 4 ? '/' : ''} ${points > 5 ? '\\' : ''} + =========== + The word is: ${display.join(' ')}. Which letter do you choose? + `); + const guess = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, { + max: 1, + time: 30000 + }); + if (!guess.size) { + await msg.say('Time!'); + break; + } + const choice = guess.first().content.toLowerCase(); + if (confirmation.includes(choice) || incorrect.includes(choice)) { + await msg.say('You have already picked that letter!'); + } else if (word.includes(choice)) { + await msg.say('Nice job!'); + for (let i = 0; i < word.length; i++) { + if (word[i] === choice) { + confirmation.push(word[i]); + display[i] = word[i]; + } + } + } else { + await msg.say('Nope!'); + incorrect.push(choice); + points++; } - } else { - await msg.say('Nope!'); - incorrect.push(choice); - points++; } + this.playing.delete(msg.guild.id); + if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`); + else return msg.say(`Too bad... It was ${word}...`); + } catch (err) { + this.playing.delete(msg.guild.id); + return msg.say(`An Error Occurred during the command: ${err.message}`); } - this.playing.delete(msg.guild.id); - if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`); - else return msg.say(`Too bad... It was ${word}...`); } }; diff --git a/package.json b/package.json index a057ad9b..95e9102e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "22.3.3", + "version": "22.3.4", "description": "A Discord Bot", "main": "Shard.js", "scripts": {