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("./../settings.json");
- const gambletimeout = new Set()
- var connection = mysql.createConnection({
- host: "127.0.0.1",
- user:"Rem",
- password:settings.mysqlpass,
- database:"rem"
- });
- function randomCash(){
- var min = 500;
- var max = 1250;
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function randomXP(){
- var min = 15
- var max = 30
- return Math.floor(Math.random() * (min - max - 1)) + min;
- }
- exports.run = (client, message, args) => {
- if (gambletimeout.has(message.author.id)) return message.reply('You can use this command every 2 seconds');
- const amountBet = args.join(" ");
- var cashBet = parseFloat(amountBet);
- console.log(`Amount Bet ${amountBet} Cash Bet ${cashBet}`)
- if (!amountBet) return message.reply('Please give me a valid ammount to gamble!')
- connection.query(`SELECT * FROM users WHERE id = '${message.author.id}'`, (err,rows) => {
- let usercash = rows[0].bal;
- if (!rows){
- connection.query(`INSERT INTO users (id, bal, xp) VALUES ('${message.author.id}', ${randomCash()}, ${randomXP()})`);
- console.log('Added ' + message.author + ' to the database (Money)');
- message.reply(`${message.author} You were not in the database. Adding now!`)
- if (err) throw err;
- }else
- if (isNaN(amountBet)) return message.reply('Please give me a number, Not a letter');
- if (cashBet < 5) return message.reply('You have to gamble at least $5');
- if (parseFloat(usercash) < cashBet){
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`${message.author} You do not have enough money to gamble $${cashBet}`);
- message.channel.send(embed)
- }else
- var result = Math.floor(Math.random() * 100 + 1)
- if (result <= 100){
- let format = cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
- var cashLost = parseFloat(usercash) - parseFloat(cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
- console.log(cashLost)
- var embed = new Discord.RichEmbed()
- .setColor(0xFF0000)
- .setDescription(`${message.author} you rolled a ${result} and lost $${format}`);
- connection.query(`UPDATE users SET bal = ${cashLost} WHERE id = '${message.author.id}'`);
- message.channel.send(embed);
- }
- if (result > 31232131232131232131){
- let format = cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
- var cashWon = parseFloat(usercash) + format
- console.log(`cashWon ${cashWon} Usercash ${usercash} format ${format} parsed format(Float) ${parseFloat(format)} parsed usercash(Float) ${parseFloat(usercash)}`)
- var embed = new Discord.RichEmbed()
- .setColor(0x00FF00)
- .setDescription(`Congrats ${message.author} you just rolled a ${result} and won $${format}`);
- connection.query(`UPDATE users SET bal = ${cashWon} WHERE id = '${message.author.id}'`);
- message.channel.send(embed);
- }
- gambletimeout.add(message.author.id);
- setTimeout(() => {
- // Removes the user from the set after 2.5 seconds
- gambletimeout.delete(message.author.id);
- }, 2000);
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement