mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Improve Hangman, Fix Discriminator
This commit is contained in:
@@ -24,11 +24,14 @@ module.exports = class HangmanCommand extends Command {
|
|||||||
.query({ api_key: WORDNIK_KEY });
|
.query({ api_key: WORDNIK_KEY });
|
||||||
const word = body.word.toLowerCase().replace(/ /g, '-');
|
const word = body.word.toLowerCase().replace(/ /g, '-');
|
||||||
let points = 0;
|
let points = 0;
|
||||||
|
let displayText = null;
|
||||||
|
let guessed = false;
|
||||||
const confirmation = [];
|
const confirmation = [];
|
||||||
const incorrect = [];
|
const incorrect = [];
|
||||||
const display = new Array(word.length).fill('_');
|
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`
|
await msg.say(stripIndents`
|
||||||
|
${displayText === null ? 'Here we go!' : displayText ? 'Good job!' : 'Nope!'}
|
||||||
\`${display.join(' ')}\`. Which letter do you choose?
|
\`${display.join(' ')}\`. Which letter do you choose?
|
||||||
\`\`\`
|
\`\`\`
|
||||||
___________
|
___________
|
||||||
@@ -53,20 +56,24 @@ module.exports = class HangmanCommand extends Command {
|
|||||||
}
|
}
|
||||||
const choice = guess.first().content.toLowerCase();
|
const choice = guess.first().content.toLowerCase();
|
||||||
if (choice === 'end') break;
|
if (choice === 'end') break;
|
||||||
if (choice.length > 1) break;
|
if (choice.length > 1 && (choice === word || choice === body.word.toLowerCase())) {
|
||||||
if (word.includes(choice)) {
|
guessed = true;
|
||||||
|
break;
|
||||||
|
} else if (word.includes(choice)) {
|
||||||
|
displayText = true;
|
||||||
for (let i = 0; i < word.length; i++) {
|
for (let i = 0; i < word.length; i++) {
|
||||||
if (word[i] !== choice) continue; // eslint-disable-line max-depth
|
if (word[i] !== choice) continue; // eslint-disable-line max-depth
|
||||||
confirmation.push(word[i]);
|
confirmation.push(word[i]);
|
||||||
display[i] = word[i];
|
display[i] = word[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
incorrect.push(choice);
|
displayText = false;
|
||||||
|
if (choice.length === 1) incorrect.push(choice);
|
||||||
points++;
|
points++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.playing.delete(msg.channel.id);
|
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}...`);
|
return msg.say(`Too bad... It was ${word}...`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.playing.delete(msg.channel.id);
|
this.playing.delete(msg.channel.id);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const Command = require('../../structures/Command');
|
const Command = require('../../structures/Command');
|
||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
|
const { trimArray } = require('../../util/Util');
|
||||||
|
|
||||||
module.exports = class DiscriminatorCommand extends Command {
|
module.exports = class DiscriminatorCommand extends Command {
|
||||||
constructor(client) {
|
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);
|
const users = this.client.users.filter(user => user.discriminator === discrim).map(user => user.username);
|
||||||
return msg.say(stripIndents`
|
return msg.say(stripIndents`
|
||||||
**Found ${users.length} users with the discriminator #${discrim}**
|
**Found ${users.length} users with the discriminator #${discrim}**
|
||||||
${users.join(', ')}
|
${trimArray(users, 50).join(', ')}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "81.0.2",
|
"version": "81.0.3",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user