diff --git a/commands/bal.js b/commands/bal.js index 6cd0c9b..1f37730 100644 --- a/commands/bal.js +++ b/commands/bal.js @@ -43,7 +43,7 @@ module.exports = { targetUserBanking = { account: { userID: interaction.member.user.id, - ballance: GuildDB.startingBalance, + balance: GuildDB.startingBalance, cash: 0.00, } } @@ -64,7 +64,7 @@ module.exports = { const User = client.users.cache.get(targetUserID); balanceEmbed.setTitle(`${User.tag}'s Balance`); - balanceEmbed.setDescription(`**Bank:** $${targetUserBanking.account.ballance}\n**Cash:** $${targetUserBanking.account.cash}`); + balanceEmbed.setDescription(`**Bank:** $${targetUserBanking.account.balance}\n**Cash:** $${targetUserBanking.account.cash}`); } else { // Show command authors balance @@ -75,7 +75,7 @@ module.exports = { banking = { account: { userID: interaction.member.user.id, - ballance: GuildDB.startingBalance, + balance: GuildDB.startingBalance, cash: 0.00, } } @@ -93,7 +93,7 @@ module.exports = { } balanceEmbed.setTitle('Your Balance'); - balanceEmbed.setDescription(`**Bank:** $${banking.account.ballance}\n**Cash:** $${banking.account.cash}`); + balanceEmbed.setDescription(`**Bank:** $${banking.account.balance.toFixed(2)}\n**Cash:** $${banking.account.cash.toFixed(2)}`); } return interaction.send({ embeds: [balanceEmbed] }); diff --git a/commands/deposit.js b/commands/deposit.js new file mode 100644 index 0000000..1dd2fdc --- /dev/null +++ b/commands/deposit.js @@ -0,0 +1,97 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "deposit", + description: "deposit cash to your balance", + usage: "[amount]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + SlashCommand: { + options: [ + { + name: "amount", + description: "amount to deposit", + value: "amount", + type: 10, + min_value: 0.01, + required: true, + } + ], + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); + + if (!banking) { + banking = { + account: { + userID: interaction.member.user.id, + balance: GuildDB.startingBalance, + cash: 0.00, + } + } + + client.dbo.collection("banking").insertOne(banking, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } + if (banking.account.cash.toFixed(2) - args[0].value < 0) { + let embed = new MessageEmbed() + .setTitle('Insufficient funds') + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + + newBalance = banking.account.balance + args[0].value; + newCash = Math.abs(banking.account.cash - args[0].value); + + client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{"account.balance":newBalance,"account.cash":newCash}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, "inventory.items.type":"wallet"}, + {$set:{"inventory.items.$.cash":newCash}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + let successEmbed = new MessageEmbed() + .setTitle('Success') + .setDescription(`Successfully deposited $${args[0].value.toFixed(2)}\nUse \`/bal\` to view your balance`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + }, + }, +} \ No newline at end of file diff --git a/commands/inventory.js b/commands/inventory.js index 3199a38..0932c8c 100644 --- a/commands/inventory.js +++ b/commands/inventory.js @@ -146,7 +146,7 @@ module.exports = { // Display wallet let item = inventory.items[0]; - let walletData = `**Cash:** $${item.cash}\n**ID:** ${item.ID.firstname ? client.exists(item.ID.firtname) : 'John'} ${item.ID.lastname ? client.exists(item.ID.lastname) : 'Doe'} | ${item.ID.dob ? client.exists(item.ID.dob) : 'N/A'}` + let walletData = `**Cash:** $${item.cash.toFixed(2)}\n**ID:** ${item.ID.firstname ? client.exists(item.ID.firtname) : 'John'} ${item.ID.lastname ? client.exists(item.ID.lastname) : 'Doe'} | ${item.ID.dob ? client.exists(item.ID.dob) : 'N/A'}` let walletEmbed = new MessageEmbed() .setTitle(`Your Wallet`) diff --git a/commands/withdraw.js b/commands/withdraw.js new file mode 100644 index 0000000..f70001b --- /dev/null +++ b/commands/withdraw.js @@ -0,0 +1,98 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "withdraw", + description: "withdraw cash from balance", + usage: "[amount]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + SlashCommand: { + options: [ + { + name: "amount", + description: "amount to withdraw", + value: "amount", + type: 10, + min_value: 0.01, + required: true, + } + ], + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking); + + if (!banking) { + banking = { + account: { + userID: interaction.member.user.id, + balance: GuildDB.startingBalance, + cash: 0.00, + } + } + + client.dbo.collection("banking").insertOne(banking, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } + + if (args[0].value > banking.account.balance) { + let embed = new MessageEmbed() + .setTitle('Insufficient funds') + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + + newBalance = banking.account.balance - args[0].value; + newCash = banking.account.cash + args[0].value; + + client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{"account.balance":newBalance,"account.cash":newCash}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, "inventory.items.type":"wallet"}, + {$set:{"inventory.items.$.cash":newCash}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + let successEmbed = new MessageEmbed() + .setTitle('Success') + .setDescription(`Successfully withdrew $${args[0].value.toFixed(2)}\nUse \`/bal\` or \`/inventory wallet\` to view your cash balance`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + }, + }, +} \ No newline at end of file