diff --git a/commands/Economy/transactions.js b/commands/Economy/transactions.js index 89005dd8..646ccd6c 100644 --- a/commands/Economy/transactions.js +++ b/commands/Economy/transactions.js @@ -18,15 +18,6 @@ class Transactions extends Command { } async run(message, args, data) { - const timestamp = Date.now() + (30 * 24 * 60 * 60 * 1000); // day hour min sec msec / 1 month - for await (const transaction of data.memberData.transactions) { - if (transaction.date < timestamp) { - const index = data.memberData.transactions.indexOf(transaction); - data.memberData.transactions.splice(index, 1); - await data.memberData.save(); - } - } - const embed = new Discord.MessageEmbed() .setAuthor({ name: message.translate("economy/transactions:EMBED_TRANSACTIONS"), diff --git a/events/ready.js b/events/ready.js index df26fd5a..60a71937 100644 --- a/events/ready.js +++ b/events/ready.js @@ -36,6 +36,10 @@ module.exports = class { const checkReminds = require("../helpers/checkReminds"); checkReminds.init(client); + // Clear transactions + const clearTransactions = require("../helpers/clearTransactions"); + clearTransactions.init(client); + // Start the dashboard if (client.config.dashboard.enabled) client.dashboard.load(client); diff --git a/helpers/autoUpdateDocs.js b/helpers/autoUpdateDocs.js index 3738ce89..5dd5903d 100644 --- a/helpers/autoUpdateDocs.js +++ b/helpers/autoUpdateDocs.js @@ -41,13 +41,8 @@ module.exports = { text += `${table(arrCat)}\n\n`; }); - if (!fs.existsSync("./dashboard/public/docs")) { - fs.mkdirSync("./dashboard/public/docs"); - fs.writeFileSync("./dashboard/public/docs/commands.md", text); - client.logger.log("Dashboard docs updated!"); - } else { - fs.writeFileSync("./dashboard/public/docs/commands.md", text); - client.logger.log("Dashboard docs updated!"); - } + if (!fs.existsSync("./dashboard/public/docs")) fs.mkdirSync("./dashboard/public/docs"); + fs.writeFileSync("./dashboard/public/docs/commands.md", text); + client.logger.log("Dashboard docs updated!"); } }; \ No newline at end of file diff --git a/helpers/clearTransactions.js b/helpers/clearTransactions.js new file mode 100644 index 00000000..60dc1634 --- /dev/null +++ b/helpers/clearTransactions.js @@ -0,0 +1,19 @@ +module.exports = { + async init(client) { + setInterval(async () => { + const timestamp = Date.now() + 30 * 24 * 60 * 60 * 1000; // day hour min sec msec / 1 month + const members = client.membersData.find({ transactions: { $gt: [] } }); + + for (const member of members) { + const transactions = member.transactions; + for await (const transaction of transactions) { + if (transaction.date < timestamp) { + const index = transactions.indexOf(transaction); + transactions.splice(index, 1); + await member.save(); + } + } + } + }, 24 * 60 * 60 * 1000); // every 24 hours + }, +}; \ No newline at end of file diff --git a/helpers/functions.js b/helpers/functions.js index dd9e9fe5..230809d3 100644 --- a/helpers/functions.js +++ b/helpers/functions.js @@ -37,7 +37,7 @@ module.exports = { }).catch(() => {}); return invite ? invite.url : "No URL"; - } return "No Invite"; + } return "No channels found for invite"; }, sortByKey(array, key) {