2019-07-24 02:08:23 +02:00
|
|
|
const { Command } = require('discord-akairo');
|
|
|
|
|
|
|
|
class guessCommand extends Command {
|
|
|
|
constructor() {
|
|
|
|
super('guess', {
|
|
|
|
aliases: ['guess'],
|
|
|
|
category: 'minigame',
|
|
|
|
description: {
|
2019-07-24 02:15:05 +02:00
|
|
|
content: 'Guess the number ( Say "stop" to stop playing )',
|
2019-07-24 02:08:23 +02:00
|
|
|
usage: '',
|
|
|
|
examples: ['']
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async exec(message) {
|
2019-07-24 04:16:13 +02:00
|
|
|
message.reply('1. Easy ( 0 - 100 )\n2. Medium ( 0 - 1000 )\n3. Hard ( 0 - 10000 )');
|
2019-07-24 02:08:23 +02:00
|
|
|
const filter = m => m.content && m.author.id == message.author.id;
|
|
|
|
message.channel.awaitMessages(filter, {time: 10000, max: 1, errors: ['time'] })
|
|
|
|
.then(messages => {
|
|
|
|
let max;
|
|
|
|
|
|
|
|
if (messages.map(messages => messages.content)[0] == 1) {
|
|
|
|
max = 100;
|
|
|
|
} else if (messages.map(messages => messages.content)[0] == 2) {
|
|
|
|
max = 1000;
|
|
|
|
} else if (messages.map(messages => messages.content)[0] == 3) {
|
|
|
|
max = 10000;
|
|
|
|
} else {
|
2019-07-24 04:16:13 +02:00
|
|
|
return message.reply('This isin\'t a valid difficulty number! Please try again.');
|
2019-07-24 02:08:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let secretnumber = Math.floor((Math.random() * max) + 1);
|
|
|
|
let numberTry = 0;
|
|
|
|
console.log(secretnumber);
|
|
|
|
|
2019-07-24 04:16:13 +02:00
|
|
|
message.reply('What is the number?');
|
|
|
|
message.channel.awaitMessages(filter, {max: 1})
|
2019-07-24 02:08:23 +02:00
|
|
|
.then(input => {
|
|
|
|
checkNumber(input.map(input => input.content)[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
function tryAgain (input) {
|
|
|
|
if (input != secretnumber) {
|
|
|
|
if (input > secretnumber) {
|
2019-07-24 04:16:13 +02:00
|
|
|
message.reply('Its less!\nWhat is the number?');
|
2019-07-24 02:08:23 +02:00
|
|
|
} else if (input < secretnumber) {
|
2019-07-24 04:16:13 +02:00
|
|
|
message.reply('Its more!\nWhat is the number?');
|
2019-07-24 02:08:23 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-24 04:16:13 +02:00
|
|
|
message.channel.awaitMessages(filter, {max: 1})
|
2019-07-24 02:08:23 +02:00
|
|
|
.then(input => {
|
|
|
|
checkNumber(input.map(input => input.content)[0]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkNumber (input) {
|
|
|
|
numberTry++;
|
2019-07-24 04:16:13 +02:00
|
|
|
if (input.toLowerCase() == 'stop') {
|
|
|
|
return message.reply('Ok, let\'s stop playing :(');
|
|
|
|
} else if (input != secretnumber) {
|
2019-07-24 02:08:23 +02:00
|
|
|
tryAgain(input);
|
|
|
|
} else {
|
|
|
|
if (numberTry > 1) {
|
2019-07-24 04:16:13 +02:00
|
|
|
return message.reply(`Congratulations! You won! It took you ${numberTry} turns!`);
|
2019-07-24 02:08:23 +02:00
|
|
|
} else {
|
2019-07-24 04:16:13 +02:00
|
|
|
return message.reply('Congratulations! You won! It took you 1 Turn!');
|
2019-07-24 02:08:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
return message.reply('Timed out');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = guessCommand;
|