fix withdraw/deposit commands

This commit is contained in:
SowinskiBraeden committed 2022-07-06 00:13:43 -07:00
1 parent fe9bc52dec
commit 8a5986a620
4 files changed
+200 -5

No files matched your search

+4 -4
View File
@@ -43,7 +43,7 @@ module.exports = {
targetUserBanking = { targetUserBanking = {
account: { account: {
userID: interaction.member.user.id, userID: interaction.member.user.id,
ballance: GuildDB.startingBalance, balance: GuildDB.startingBalance,
cash: 0.00, cash: 0.00,
} }
} }
@@ -64,7 +64,7 @@ module.exports = {
const User = client.users.cache.get(targetUserID); const User = client.users.cache.get(targetUserID);
balanceEmbed.setTitle(`${User.tag}'s Balance`); 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 { } else {
// Show command authors balance // Show command authors balance
@@ -75,7 +75,7 @@ module.exports = {
banking = { banking = {
account: { account: {
userID: interaction.member.user.id, userID: interaction.member.user.id,
ballance: GuildDB.startingBalance, balance: GuildDB.startingBalance,
cash: 0.00, cash: 0.00,
} }
} }
@@ -93,7 +93,7 @@ module.exports = {
} }
balanceEmbed.setTitle('Your Balance'); 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] }); return interaction.send({ embeds: [balanceEmbed] });
+97
View File
@@ -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] });
},
},
}
+1 -1
View File
@@ -146,7 +146,7 @@ module.exports = {
// Display wallet // Display wallet
let item = inventory.items[0]; 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() let walletEmbed = new MessageEmbed()
.setTitle(`Your Wallet`) .setTitle(`Your Wallet`)
+98
View File
@@ -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] });
},
},
}