97 lines
3.1 KiB
JavaScript
97 lines
3.1 KiB
JavaScript
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.toFixed(2) - 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] });
|
|
},
|
|
},
|
|
} |