1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Haha-Yes/commands/minigame/guess.js

78 lines
2.2 KiB
JavaScript

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