From 3c560b5c7acd33ab3f22a6a3da160e5c1b6c69e9 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Sun, 9 Oct 2022 14:26:22 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Economy/bank.js | 9 ++++----- commands/Economy/number.js | 4 ++-- commands/Economy/pay.js | 24 ++++++++++++++++-------- commands/Economy/rob.js | 1 + commands/Economy/slots.js | 3 ++- commands/Economy/tictactoe.js | 6 +++--- commands/Economy/work.js | 6 +++--- events/MessageHandler.js | 2 +- helpers/cleanup.js | 28 +++++++++++++++++++++------- 9 files changed, 53 insertions(+), 30 deletions(-) diff --git a/commands/Economy/bank.js b/commands/Economy/bank.js index 74739421..05fcec36 100644 --- a/commands/Economy/bank.js +++ b/commands/Economy/bank.js @@ -48,19 +48,18 @@ class Bank extends BaseCommand { if (isNaN(credits) || credits < 1) return interaction.error("misc:OPTION_NAN_ALL"); if (data.memberData.money < credits) return interaction.error("economy/bank:NOT_ENOUGH_CREDIT", { money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); + data.memberData.money -= credits; + data.memberData.bankSold += credits; + await data.memberData.save(); + const info = { user: interaction.translate("economy/transactions:BANK"), amount: credits, date: Date.now(), type: "send" }; - data.memberData.transactions.push(info); - data.memberData.money -= credits; - data.memberData.bankSold += credits; - await data.memberData.save(); - interaction.success("economy/bank:SUCCESS_DEP", { money: `**${credits}** ${client.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` }); diff --git a/commands/Economy/number.js b/commands/Economy/number.js index 5fef8ec5..59d07032 100644 --- a/commands/Economy/number.js +++ b/commands/Economy/number.js @@ -82,16 +82,16 @@ class Number extends BaseCommand { guildId: interaction.guildId }); + memberData.money += won; + const info = { user: interaction.translate("economy/transactions:NUMBERS"), amount: won, date: Date.now(), type: "got" }; - data.memberData.transactions.push(info); - memberData.money += won; await memberData.save(); } collector.stop(); diff --git a/commands/Economy/pay.js b/commands/Economy/pay.js index 4907b0a4..1ff5e8db 100644 --- a/commands/Economy/pay.js +++ b/commands/Economy/pay.js @@ -53,20 +53,28 @@ class Pay extends BaseCommand { guildId: interaction.guildId }); - const info = { - user: member.user.tag, - amount: amount, - date: Date.now(), - type: "send" - }; - - data.memberData.transactions.push(info); data.memberData.money -= amount; await data.memberData.save(); memberData.money += amount; memberData.save(); + const info1 = { + user: member.user.tag, + amount: amount, + date: Date.now(), + type: "send" + }; + data.memberData.transactions.push(info1); + + const info2 = { + user: member.user.tag, + amount: amount, + date: Date.now(), + type: "got" + }; + data.memberData.transactions.push(info2); + interaction.success("economy/pay:SUCCESS", { user: member.toString(), amount: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}` diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 187f4265..3e65de95 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -48,6 +48,7 @@ class Rob extends BaseCommand { guildId: interaction.guildId }); if (amount > memberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: member.toString() }); + const isInCooldown = memberData.cooldowns.rob || 0; if (isInCooldown) { if (isInCooldown > Date.now()) return interaction.error("economy/rob:COOLDOWN", { user: member.toString() }); diff --git a/commands/Economy/slots.js b/commands/Economy/slots.js index 3e0d9833..36d38da0 100644 --- a/commands/Economy/slots.js +++ b/commands/Economy/slots.js @@ -101,6 +101,8 @@ class Slots extends BaseCommand { const toAdd = credits - amount; + data.memberData.money += toAdd; + const info = { user: interaction.translate("economy/slots:DESCRIPTION"), amount: toAdd, @@ -108,7 +110,6 @@ class Slots extends BaseCommand { type: "got" }; data.memberData.transactions.push(info); - data.memberData.money += toAdd; if (!data.userData.achievements.slots.achieved) { data.userData.achievements.slots.progress.now += 1; diff --git a/commands/Economy/tictactoe.js b/commands/Economy/tictactoe.js index 2ca298cf..41850320 100644 --- a/commands/Economy/tictactoe.js +++ b/commands/Economy/tictactoe.js @@ -45,6 +45,9 @@ class TicTacToe extends BaseCommand { guildId: interaction.guildId }); + memberData.money += 100; + await memberData.save(); + const info = { user: interaction.translate("economy/transactions:TTT"), amount: 100, @@ -52,9 +55,6 @@ class TicTacToe extends BaseCommand { type: "got" }; memberData.transactions.push(info); - - memberData.money += 100; - await memberData.save(); }); } } diff --git a/commands/Economy/work.js b/commands/Economy/work.js index ce6c78cf..6926b4ab 100644 --- a/commands/Economy/work.js +++ b/commands/Economy/work.js @@ -98,16 +98,16 @@ class Work extends BaseCommand { ]); } + data.memberData.money += won; + await data.memberData.save(); + const info = { user: interaction.translate("economy/work:SALARY"), amount: won, date: Date.now(), type: "got" }; - data.memberData.transactions.push(info); - data.memberData.money += won; - await data.memberData.save(); const messageOptions = { embeds: [embed] diff --git a/events/MessageHandler.js b/events/MessageHandler.js index abc8da7d..fde55198 100644 --- a/events/MessageHandler.js +++ b/events/MessageHandler.js @@ -61,7 +61,7 @@ class MessageCreate extends BaseEvent { await data.userData.save(); message.replyT("general/afk:DELETED", { username: message.author.username - }); + }, { mention: true }); } message.mentions.users.forEach(async (u) => { diff --git a/helpers/cleanup.js b/helpers/cleanup.js index 6f46b5df..53b10017 100644 --- a/helpers/cleanup.js +++ b/helpers/cleanup.js @@ -1,10 +1,26 @@ +// Thanks Stackoverflow <3 +function setDaysTimeout(callback, days) { + // 86400 seconds in a day + const msInDay = 86400 * 1000; + + let dayCount = 0; + const timer = setInterval(function () { + dayCount++; // a day has passed + + if (dayCount === days) { + clearInterval(timer); + callback.apply(this, []); + } + }, msInDay); +} + /** * * @param {import("../base/JaBa")} client */ module.exports.init = async function (client) { - setInterval(async () => { - const timestamp = Date.now() + (30 * 24 * 60 * 60 * 1000); // 1 month + setDaysTimeout(async () => { + const timestamp = Date.now() + (29 * 24 * 60 * 60 * 1000); // 29 days const members = client.membersData.find({ transactions: { $gt: [] } }); for (const member of members) { @@ -17,10 +33,9 @@ module.exports.init = async function (client) { } } } - }, (7 * 24 * 60 * 60 * 1000)); // every 7 days + }, 14); - /* - setInterval(async () => { + setDaysTimeout(async () => { client.usersData.find({}, function (err, res) { for (const user of res) { client.users.fetch(user.id).then(u => { @@ -32,6 +47,5 @@ module.exports.init = async function (client) { }); } }); - }, (7 * 24 * 60 * 60 * 1000)); // every 7 days - */ + }, 30); }; \ No newline at end of file