odin/libs/games.js
2022-11-27 21:09:37 +01:00

56 lines
No EOL
1.6 KiB
JavaScript

function rockPaperScissorsAgainstBot(userChoice, ctx, bot) {
const choices = ["rock", "paper", "scissors"];
if (choices.includes(userChoice) == true)
{
const botChoice = choices[Math.floor(Math.random() * choices.length)];
bot.telegram.sendMessage(ctx.chat.id, "You chose " + userChoice + " and I chose " + botChoice, {})
//wait 50ms
setTimeout(function() {
if (userChoice == botChoice)
{
bot.telegram.sendMessage(ctx.chat.id, "It's a tie!", {});
}
else if (userChoice == "rock")
{
if (botChoice == "paper")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Paper beats rock.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Rock beats scissors.", {});
}
}
else if (userChoice == "paper")
{
if (botChoice == "scissors")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Scissors beats paper.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Paper beats rock.", {});
}
}
else if (userChoice == "scissors")
{
if (botChoice == "rock")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Rock beats scissors.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Scissors beats paper.", {});
}
}
}, 50);
} else
{
bot.telegram.sendMessage(ctx.chat.id, "Please choose between rock, paper and scisors", {});
}
}
module.exports = { rockPaperScissorsAgainstBot };