Files
quarksBot/commands/money.js
T

169 lines
5.6 KiB
JavaScript

const { MessageEmbed } = require('discord.js');
module.exports = {
name: "money",
debug: false,
description: "add/remove money from user",
usage: "[opt.] [user] [amount]",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: ["MANAGE_GUILD"],
},
SlashCommand: {
options: [
{
name: "add",
description: "Add money to user",
value: "add",
type: 1,
options: [
{
name: "user",
description: "User to give money",
value: "user",
type: 6,
required: true,
},
{
name: "amount",
description: "The amount to add to balance",
value: 1000.00,
type: 10,
required: true,
}
],
},
{
name: "remove",
description: "Remove money from user",
value: "remove",
type: 1,
options: [
{
name: "user",
description: "User to remove money from",
value: "user",
type: 6,
required: true,
},
{
name: "amount",
description: "The amount to add to balance",
value: 1000.00,
type: 10,
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.`);
}
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
let canUseCommand = false;
if (permissions.includes("MANAGE_GUILD")) canUseCommand = true;
if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true;
if (!canUseCommand) return interaction.send('You don\'t have the permissions to use this command.');
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking);
if (!banking) {
banking = {
userID: targetUserID,
guidls: {
[guildID]: {
account: {
balance: GuildDB.startingBalance,
cash: 0.00,
}
}
}
}
// Register inventory for user
let newBank = new Bank();
newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance);
newBank.save()
.catch(err => {
if (err) {
client.log(err);
const embed = new MessageEmbed()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor("RED")
return interaction.send({ embeds: [embed] });
}
});
} else banking = banking.banking;
if (!client.exists(banking.guilds[GuildDB.serverID])) {
const success = addBank(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance);
if (!success) {
client.log(err);
const embed = new MessageEmbed()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor("RED")
return interaction.send({ embeds: [embed] });
}
}
if (args[0].name == "add") {
// add money to user
let newBalance = banking.guilds[GuildDB.serverID].account.balance + args[0].options[1].value;
client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance}}, function(err, res) {
if (err) {
client.log(err);
const embed = new MessageEmbed()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor("RED")
return interaction.send({ embeds: [embed] });
}
});
let successEmbed = new MessageEmbed()
.setDescription(`Successfully added $${args[0].options[1].value.toFixed(2)} to <@${targetUserID}>'s balance`)
.setColor('GREEN');
return interaction.send({ embeds: [successEmbed] });
} else if (args[0].name == "remove") {
// remove money from user
let newBalance = banking.guilds[GuildDB.serverID].account.balance - args[0].options[1].value;
client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance}}, function(err, res) {
if (err) {
client.log(err);
const embed = new MessageEmbed()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor("RED")
return interaction.send({ embeds: [embed] });
}
});
let successEmbed = new MessageEmbed()
.setDescription(`Successfully removed $${args[0].options[1].value.toFixed(2)} from <@${targetUserID}>'s balance`)
.setColor('GREEN');
return interaction.send({ embeds: [successEmbed] });
}
},
},
}