2016-08-14 18:49:23 -04:00
|
|
|
var Command = require('./Command.js');
|
|
|
|
var grabTokens = require('../helpers/grabTokens.js');
|
|
|
|
var promise = require('promise-polyfill');
|
|
|
|
|
2016-08-14 20:15:07 -04:00
|
|
|
var condition = function(text, userData) {
|
2016-08-14 18:49:23 -04:00
|
|
|
var tokens = grabTokens(text);
|
2016-08-14 20:15:07 -04:00
|
|
|
return tokens.contain("play") && (tokens.contain("rock") && tokens.contain("paper") && tokens.contain("scissors")) && (tokens.contain("rozbot") || userData.privateMessage)
|
2016-08-14 18:49:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = new Command("RockPaperScissors", condition, function(text, send, userData) {
|
|
|
|
userData.prompt("Make your move").then(function(choice) {
|
|
|
|
choice = choice.toLowerCase();
|
|
|
|
|
|
|
|
var options = ["rock", "paper", "scissors"]
|
|
|
|
|
|
|
|
//If player doesn't choice rock, paper, or scissors
|
|
|
|
if (options.indexOf(choice) === -1) {
|
|
|
|
send("Aw you tricked me, that wasn't an option");
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var computerChoice = options[Math.floor(Math.random() * options.length)];
|
|
|
|
|
|
|
|
send("I chose " + computerChoice);
|
|
|
|
|
|
|
|
//Game logic
|
|
|
|
if (choice === "rock") {
|
|
|
|
if (computerChoice === "rock") {
|
|
|
|
send("It's a tie..");
|
|
|
|
} else if (computerChoice === "paper") {
|
|
|
|
send("You lose..");
|
|
|
|
} else if (computerChoice === "scissors") {
|
|
|
|
send("You win!");
|
|
|
|
}
|
|
|
|
} else if (choice === "paper") {
|
|
|
|
if (computerChoice === "rock") {
|
|
|
|
send("You win!");
|
|
|
|
} else if (computerChoice === "paper") {
|
|
|
|
send("It's a tie..");
|
|
|
|
} else if (computerChoice === "scissors") {
|
|
|
|
send("You lose..");
|
|
|
|
}
|
|
|
|
} else if (choice === "scissors") {
|
|
|
|
if (computerChoice === "rock") {
|
|
|
|
send("You lose..");
|
|
|
|
} else if (computerChoice === "paper") {
|
|
|
|
send("You win!");
|
|
|
|
} else if (computerChoice === "scissors") {
|
|
|
|
send("It's a tie..");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|