Skip to content

Commit

Permalink
added last interaction check to /roulette
Browse files Browse the repository at this point in the history
  • Loading branch information
vb2007 committed Aug 6, 2024
1 parent 789c335 commit f8c8d9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commands/economy/rob.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
const query = await db.query("SELECT userId, lastRobTime FROM economy WHERE userId = ?", [interaction.user.id]);
const userId = query[0]?.userId || null;
const lastRobTime = query[0]?.lastRobTime || null;
const nextApprovedRobTimeUTC = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60000 - 30 * 60000);
const nextApprovedRobTimeUTC = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60000 - 30 * 60000); //30 minutes

const targetUserId = interaction.options.getUser("target").id;

Expand Down
16 changes: 13 additions & 3 deletions commands/economy/roulette.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ module.exports = {
const interactionUserId = interaction.user.id;
const amount = interaction.options.getInteger("amount");

var query = await db.query("SELECT balance FROM economy WHERE userId = ?", [interactionUserId]);
var userBalance = query[0]?.balance;
const query = await db.query("SELECT balance, lastRouletteTime FROM economy WHERE userId = ?", [interactionUserId]);
const userBalance = query[0]?.balance;

if (userBalance < amount) {
const lastRouletteTime = query[0]?.lastRouletteTime;
const nextApprovedRouletteTimeUTC = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60000 - 15 * 60000); //15 minutes

if(lastRouletteTime >= nextApprovedRouletteTimeUTC) {
const remainingTimeInSeconds = Math.ceil((lastRouletteTime.getTime() - nextApprovedRouletteTimeUTC.getTime()) / 1000);
const remainingMinutes = Math.floor(remainingTimeInSeconds / 60);
const remainingSeconds = remainingTimeInSeconds % 60;

var replyContent = `You've already played roulette in the last 15 minutes.\nPlease wait **${remainingMinutes} minute(s)** and **${remainingSeconds} second(s)** before trying to **play roulette** again.`;
}
else if (userBalance < amount) {
var replyContent = `You can't play with that much money!\nYour current balance is only \`$${userBalance}\`.`;
}
else if (amount <= 0) {
Expand Down

0 comments on commit f8c8d9a

Please sign in to comment.