From f8c8d9a19b75d102a64e4730cbfb129856aaf9e5 Mon Sep 17 00:00:00 2001 From: vb2007 Date: Tue, 6 Aug 2024 10:25:08 +0200 Subject: [PATCH] added last interaction check to /roulette --- commands/economy/rob.js | 2 +- commands/economy/roulette.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/commands/economy/rob.js b/commands/economy/rob.js index 1b9bf6c..e4cd083 100644 --- a/commands/economy/rob.js +++ b/commands/economy/rob.js @@ -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; diff --git a/commands/economy/roulette.js b/commands/economy/roulette.js index 9da2200..f85d2e5 100644 --- a/commands/economy/roulette.js +++ b/commands/economy/roulette.js @@ -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) {