const mongoose = require ("mongoose") const botconfig = require("../botconfig.json") //CONNECT TO DATABASE mongoose.connect(botconfig.mongoPass, { useNewUrlParser: true, useUnifiedTopology: true, }); //MODELS const Data = require("../models/data.js") module.exports.run = async (bot, message, args) => { Data.findOne({ userID: message.author.id }, (err, data) => { if(err) console.log(err); if(!data) { const newData = new Data({ name: message.author.username, userID: message.author.id, lb: "all", money: 0, daily: 0, }) data.save().catch(err => console.log(err)); return message.channel.reply("You don't have any money to gamble with!"); } else { var maxBet = 10000; if(data.money <= 0) return message.reply("You don't have any money!") if(!args[0]) return message.reply("Please specify the bet amount.") try { var bet = parseFloat(args[0]); } catch { return message.reply("You can only enter whole numbers."); } if(bet != Math.floor(bet)) return message.reply("You can only enter whole numbers.") if(data.money < bet) return message.reply("You don't have enough money to bet!") if(bet > maxBet) return message.reply(`The maximum bet is ${maxBet.toLocaleString()}.`) let chances = ["win", "lose"] var pick = chances[Math.floor(Math.random() * chances.length)]; if(pick == "lose") { data.money -= bet; data.save().catch(err => console.log(err)); return message.reply(`You lost the bet. New Balance is ${data.money}`) } else { data.money += bet; data.save().catch(err => console.log(err)); return message.reply(`You won the bet! New Balance is ${data.money}`) } } module.exports.help = { name: "gamble", aliases: ["bet"] }