Skip to content

Commit

Permalink
replaced roulette switch case
Browse files Browse the repository at this point in the history
  • Loading branch information
vb2007 committed Aug 6, 2024
1 parent cca1f65 commit 982138c
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions commands/economy/roulette.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ module.exports = {
var replyContent = `You can't play without money.\nPlease enter a positive amount that's in you balance range.\nYour current balance is \`$${userBalance}\`.`;
}
else {
const validColors = ["red", "black", "green"];
const guessedColor = interaction.options.getString("color");

const randomOutcome = generate.generateRandomOutcome();
const randomColor = randomOutcome.color;
const randomNumber = randomOutcome.number;

switch (guessedColor) {
case randomColor && guessedColor === "green":
if(!validColors.includes(guessedColor)) {
var replyContent = "The color you've chosen is invalid.\nPlease choose from *red*, *black* or *green*.";
}
else if (guessedColor === randomColor) {
if (guessedColor === "green") {
await db.query("UPDATE economy SET balance = balance + ?, lastRouletteTime = ? WHERE userId = ?",
[
amount * 35,
Expand All @@ -68,9 +72,9 @@ module.exports = {
]
);

var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(randomColor)}**.\nYou hit the jackpot! :money_mouth:`;
break;
case randomColor:
var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(guessedColor)}**.\nYou hit the jackpot! :money_mouth:`;
}
else {
await db.query("UPDATE economy SET balance = balance + ?, lastRouletteTime = ? WHERE userId = ?",
[
amount * 2,
Expand All @@ -79,21 +83,19 @@ module.exports = {
]
);

var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(randomColor)}** as well! :money_mouth:`;
break;
case "red" || "black" || "green":
await db.query("UPDATE economy SET balance = balance - ?, lastRouletteTime = ? WHERE userId = ?",
[
amount,
new Date().toISOString().slice(0, 19).replace('T', ' '),
interactionUserId
]
);
var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(guessedColor)}** as well! :money_mouth:`;
}
}
else {
await db.query("UPDATE economy SET balance = balance - ?, lastRouletteTime = ? WHERE userId = ?",
[
amount,
new Date().toISOString().slice(0, 19).replace('T', ' '),
interactionUserId
]
);

var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(randomColor)}**.\nMaybe try your luck again. :upside_down:`;
break;
default:
var replyContent = "The color you've chosen is invalid.\nPlease choose from *red*, *black* or *green*.";
var replyContent = `The ball landed on **${format.formatRouletteColor(randomColor)} ${randomNumber}**.\nYour guess was **${format.formatRouletteColor(guessedColor)}**.\nMaybe try your luck again. :upside_down:`;
}
}
}
Expand Down

0 comments on commit 982138c

Please sign in to comment.