const { MessageEmbed } = require("discord.js"); const { red, blurple } = require("../../other/texts/colors.json"); const { economy: { authorEconomy, targetUserEconomy }, noAvailabilityFound, disabled } = require("../../other/texts/permissions.json"); const ms = require("parse-ms"); // These are the models that we are going to be requiring to connect to the database. const Data = require("../../models/users/economy/data.js"); const Availability = require("../../models/guilds/availability/economy/availability.js"); module.exports = { config: { name: "pay", aliases: ["give", "donate"], usage: "!pay <@user> ", category: "economy", description: "Pay a user coins from your money account!", noalias: "No Aliases", accessableby: "Members" }, run: async (bot, message, args) => { if (!message.channel.permissionsFor(message.guild.me).has(['VIEW_CHANNEL', 'SEND_MESSAGES', 'EMBED_LINKS'])) return; Availability.findOne({ serverID: message.guild.id }, async (err, availability) => { if (err) console.log(err); if (!availability) { const noAvailability = new MessageEmbed() .setColor(red) .setDescription(noAvailabilityFound) return await message.channel.send(noAvailability); } else { if (availability.pay === false) { const disable = new MessageEmbed() .setColor(red) .setDescription(disabled) return await message.channel.send(disable); } else { let timeout = 604800000; Data.findOne({ userID: message.author.id }, async (err, authorData) => { if (err) console.log(err); if (!authorData) { const noAccount = new MessageEmbed() .setColor(red) .setDescription(authorEconomy) return await message.channel.send(noAccount); } else { if (timeout - (Date.now() - authorData.newAccount) > 0) { let time = ms(timeout - (Date.now - authorData.newAccount)); const timeoutEmbed = new MessageEmbed() .setColor(red) .setDescription(`❌ Your account is too new to pay other users.`) return await message.channel.send(timeoutEmbed); } else { let user = message.mentions.members.first() || bot.users.cache.get(args[0]); Data.findOne({ userID: user.id }, async (err, userData) => { if (err) console.log(err); const embedError = new MessageEmbed() .setColor(red) if (authorData.passive === true) { embedError.setDescription(`❌ You are currently in **Passive Mode**.`); return await message.channel.send(embedError); }; if (!user) { embedError.setDescription("❌ Please specify a user you are wishing to pay!"); return await message.channel.send(embedError); }; if (user.id === message.author.id) { embedError.setDescription("❌ You cannot pay yourself, silly!"); return await message.channel.send(embedError); }; if (!args[1]) { embedError.setDescription("❌ Please specify the amount you are willing to pay for the said user!"); return await message.channel.send(embedError); }; if (isNaN(args[1])) { embedError.setDescription("❌ You can only enter whole numbers."); return await message.channel.send(embedError); }; if (parseInt(args[1]) > authorData.money) { embedError.setDescription("❌ Sorry, you don't have enough money in your money account!"); return await message.channel.send(embedError); }; if (parseInt(args[1]) < 1) { embedError.setDescription("❌ You cannot pay less than **$1**."); return await message.channel.send(embedError); }; if (message.content.includes('-')) { embedError.setDescription("❌ You cannot send negative numbers."); return await message.channel.send(embedError); }; if (userData.passive === true) { embedError.setDescription(`❌ **${bot.users.cache.get(user.id).username}** is currently in **Passive Mode**.`); return await message.channel.send(embedError); }; /* Tax Calculation */ if (parseInt(args[1]) >= 1 && parseInt(args[1]) <= 25000) { var amount = parseInt(args[1]) * 1; var tax = "0"; } else if (parseInt(args[1]) >= 25001 && parseInt(args[1]) <= 50000) { var amount = parseInt(args[1]) * 0.99; var tax = "1"; } else if (parseInt(args[1]) >= 50001 && parseInt(args[1]) <= 100000) { var amount = parseInt(args[1]) * 0.97; var tax = "3"; } else if (parseInt(args[1]) >= 100001 && parseInt(args[1]) <= 250000) { var amount = parseInt(args[1]) * 0.95; var tax = "5"; } else if (parseInt(args[1]) >= 250001 && parseInt(args[1]) <= 500000) { var amount = parseInt(args[1]) * 0.92; var tax = "8"; } else if (parseInt(args[1]) >= 500000) { var amount = parseInt(args[1]) * 0.85; var tax = "15"; }; if (!userData) { const noArgsAccount = new MessageEmbed() .setColor(red) .setDescription(targetUserEconomy.replace("${user.user.username}", user.user.username)) return await message.channel.send(noArgsAccount); } else { userData.money += parseInt(amount); authorData.money -= parseInt(args[1]); userData.save().catch(err => console.log(err)); }; let embed = new MessageEmbed() .setDescription(`**${message.author.username}** has successfully paid **${bot.users.cache.get(user.id).username}** the amount of **$${parseInt(amount).toLocaleString()}** after a **${tax}%** tax rate.`) .setColor(blurple) await message.channel.send(embed); const Inventory = require("../../models/users/economy/inventory.js"); const inventory = await Inventory.findOne({ userID: message.author.id }); let upgrade = Math.floor(Math.random() * 100) + 1; if (!inventory) { const newInventory = new Inventory({ userID: message.author.id, inventory: { ['upgrades']: (upgrade >= 1 && upgrade <= 10) ? 1 : 0 }, }).save().catch(err => console.log(err)); } else if (inventory) { if (upgrade >= 1 && upgrade <= 10) { const hasUpgrade = Object.keys(inventory.inventory).includes('upgrades'); if (!hasUpgrade) { inventory.inventory['upgrades'] = 1; } else { inventory.inventory['upgrades']++; }; }; await Inventory.findOneAndUpdate({ userID: message.author.id }, inventory); }; authorData.bankLimit += 5; authorData.save().catch(err => console.log(err)); }); }; }; }); }; }; }); }, };