Advertisement
Guest User

Fix it 4 me

a guest
Apr 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const mysql = require("mysql");
  3. const settings = require("./../settings.json");
  4. const gambletimeout = new Set()
  5.  
  6. var connection = mysql.createConnection({
  7. host: "127.0.0.1",
  8. user:"Rem",
  9. password:settings.mysqlpass,
  10. database:"rem"
  11. });
  12.  
  13. function randomCash(){
  14. var min = 500;
  15. var max = 1250;
  16.  
  17. return Math.floor(Math.random() * (max - min + 1)) + min;
  18. }
  19.  
  20. function randomXP(){
  21. var min = 15
  22. var max = 30
  23.  
  24. return Math.floor(Math.random() * (min - max - 1)) + min;
  25. }
  26.  
  27. exports.run = (client, message, args) => {
  28.  
  29. if (gambletimeout.has(message.author.id)) return message.reply('You can use this command every 2 seconds');
  30.  
  31. const amountBet = args.join(" ");
  32. var cashBet = parseFloat(amountBet);
  33.  
  34. console.log(`Amount Bet ${amountBet} Cash Bet ${cashBet}`)
  35.  
  36. if (!amountBet) return message.reply('Please give me a valid ammount to gamble!')
  37. connection.query(`SELECT * FROM users WHERE id = '${message.author.id}'`, (err,rows) => {
  38. let usercash = rows[0].bal;
  39.  
  40. if (!rows){
  41. connection.query(`INSERT INTO users (id, bal, xp) VALUES ('${message.author.id}', ${randomCash()}, ${randomXP()})`);
  42. console.log('Added ' + message.author + ' to the database (Money)');
  43. message.reply(`${message.author} You were not in the database. Adding now!`)
  44. if (err) throw err;
  45. }else
  46.  
  47. if (isNaN(amountBet)) return message.reply('Please give me a number, Not a letter');
  48.  
  49. if (cashBet < 5) return message.reply('You have to gamble at least $5');
  50. if (parseFloat(usercash) < cashBet){
  51. var embed = new Discord.RichEmbed()
  52. .setColor(0xFF0000)
  53. .setDescription(`${message.author} You do not have enough money to gamble $${cashBet}`);
  54. message.channel.send(embed)
  55. }else
  56.  
  57. var result = Math.floor(Math.random() * 100 + 1)
  58.  
  59. if (result <= 100){
  60. let format = cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
  61.  
  62. var cashLost = parseFloat(usercash) - parseFloat(cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
  63. console.log(cashLost)
  64.  
  65. var embed = new Discord.RichEmbed()
  66. .setColor(0xFF0000)
  67. .setDescription(`${message.author} you rolled a ${result} and lost $${format}`);
  68. connection.query(`UPDATE users SET bal = ${cashLost} WHERE id = '${message.author.id}'`);
  69. message.channel.send(embed);
  70. }
  71.  
  72. if (result > 31232131232131232131){
  73. let format = cashBet.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
  74. var cashWon = parseFloat(usercash) + format
  75. console.log(`cashWon ${cashWon} Usercash ${usercash} format ${format} parsed format(Float) ${parseFloat(format)} parsed usercash(Float) ${parseFloat(usercash)}`)
  76. var embed = new Discord.RichEmbed()
  77. .setColor(0x00FF00)
  78. .setDescription(`Congrats ${message.author} you just rolled a ${result} and won $${format}`);
  79. connection.query(`UPDATE users SET bal = ${cashWon} WHERE id = '${message.author.id}'`);
  80. message.channel.send(embed);
  81. }
  82.  
  83. gambletimeout.add(message.author.id);
  84. setTimeout(() => {
  85. // Removes the user from the set after 2.5 seconds
  86. gambletimeout.delete(message.author.id);
  87. }, 2000);
  88. })
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement