Improve Hangman, Fix Discriminator

This commit is contained in:
Daniel Odendahl Jr
2018-07-07 03:37:46 +00:00
parent 3f98864358
commit cb9aebbdf2
3 changed files with 15 additions and 7 deletions
+12 -5
View File
@@ -24,11 +24,14 @@ module.exports = class HangmanCommand extends Command {
.query({ api_key: WORDNIK_KEY });
const word = body.word.toLowerCase().replace(/ /g, '-');
let points = 0;
let displayText = null;
let guessed = false;
const confirmation = [];
const incorrect = [];
const display = new Array(word.length).fill('_');
while (word.length !== confirmation.length && points < 7) {
while (word.length !== confirmation.length && points < 6) {
await msg.say(stripIndents`
${displayText === null ? 'Here we go!' : displayText ? 'Good job!' : 'Nope!'}
\`${display.join(' ')}\`. Which letter do you choose?
\`\`\`
___________
@@ -53,20 +56,24 @@ module.exports = class HangmanCommand extends Command {
}
const choice = guess.first().content.toLowerCase();
if (choice === 'end') break;
if (choice.length > 1) break;
if (word.includes(choice)) {
if (choice.length > 1 && (choice === word || choice === body.word.toLowerCase())) {
guessed = true;
break;
} else if (word.includes(choice)) {
displayText = true;
for (let i = 0; i < word.length; i++) {
if (word[i] !== choice) continue; // eslint-disable-line max-depth
confirmation.push(word[i]);
display[i] = word[i];
}
} else {
incorrect.push(choice);
displayText = false;
if (choice.length === 1) incorrect.push(choice);
points++;
}
}
this.playing.delete(msg.channel.id);
if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`);
if (word.length === confirmation.length || guessed) return msg.say(`You won, it was ${word}!`);
return msg.say(`Too bad... It was ${word}...`);
} catch (err) {
this.playing.delete(msg.channel.id);
+2 -1
View File
@@ -1,5 +1,6 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const { trimArray } = require('../../util/Util');
module.exports = class DiscriminatorCommand extends Command {
constructor(client) {
@@ -29,7 +30,7 @@ module.exports = class DiscriminatorCommand extends Command {
const users = this.client.users.filter(user => user.discriminator === discrim).map(user => user.username);
return msg.say(stripIndents`
**Found ${users.length} users with the discriminator #${discrim}**
${users.join(', ')}
${trimArray(users, 50).join(', ')}
`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "81.0.2",
"version": "81.0.3",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {