Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const mysql = require("mysql");
- const settings = require("./../Constants/settings.json");
- const colors = require("./../Constants/colors.json");
- const timeout = new Set()
- var connection = mysql.createConnection({
- host: settings.EndPoint,
- user:"rem",
- password:settings.mysqlpass,
- database:"rem"
- });
- function formatBal(bal){
- return bal.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
- }
- exports.run = (client, message, args, args2, argresult) => {
- let amount = argresult;
- connection.query(`SELECT * FROM users WHERE id = '${message.author.id}'`, (err,rows) => {
- if(err) throw(err);
- if (rows.length < 1){
- connection.query(`INSERT INTO users (id, bal, xp) VALUES ('${message.author.id}', ${randomCash()}, ${randomXP()})`);
- }else{
- var bal = parseFloat(rows[0].bal)
- var bank = parseFloat(rows[0].bank)
- if (!amount){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`${message.author} Please give me a valid amount (d!deposit 100)`)
- message.channel.send(embed)
- }else if (parseFloat(amount) < 100){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`Sorry ${message.author} You cannot deposit less than $100`)
- message.channel.send(embed)
- }else if (parseFloat(amount) > bal){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`Sorry ${message.author} You do not have enough money to deposit $${amount}, You only have $${bal}`)
- message.channel.send(embed)
- }else if (bal === 0){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`Sorry ${message.author} You have nothing to deposit!`)
- message.channel.send(embed)
- }else if (amount === "all" || amount === "All" || amount === "ALL"){
- if (bal < 100){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`Sorry ${message.author} You cannot deposit less than $100`)
- message.channel.send(embed)
- }else if (bal + bank > 1000000){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`Sorry ${message.author} You cannot have over $1,000,000 in your bank account`)
- message.channel.send(embed)
- }else{
- connection.query(`UPDATE users SET bal = ${bal - bal}, bank = ${bank + bal} WHERE id = '${message.author.id}'`);
- var embed = new Discord.RichEmbed()
- .setColor(0x00FF00)
- .setTitle("Money Deposited")
- .setDescription(`${message.author} You just deposited $${formatBal(bal)} into your bank\n\n You now have $${formatBal(bal + bank)} in your bank account and $${formatBal(bal - bal)} cash`)
- message.channel.send(embed)
- }
- }else{
- if (isNaN(amount)){
- var embed = new Discord.RichEmbed()
- .setColor(colors.red)
- .setDescription(`Please give me a valid positive number. Not a letter or a negative number.`)
- message.channel.send(embed)
- }else{
- connection.query(`UPDATE users SET bal = ${bal - parseFloat(amount)}, bank = ${bank + parseFloat(amount)} WHERE id = '${message.author.id}'`);
- var embed = new Discord.RichEmbed()
- .setColor(0x00FF00)
- .setTitle("Money Deposited")
- .setDescription(`${message.author} You just deposited $${argresult} into your bank\n\n You now have $${formatBal(parseFloat(amount) + bank)} in your bank account and $${formatBal(bal - parseFloat(amount))} cash`)
- message.channel.send(embed)
- }
- }
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement