From 17ad013376019d54cc35e8a8dc623820bbc2e9ff Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 31 Jul 2022 17:14:55 -0700 Subject: [PATCH] revamp add/remove money command --- commands/add-money.js | 88 --------------------- commands/money.js | 164 +++++++++++++++++++++++++++++++++++++++ commands/remove-money.js | 29 ------- 3 files changed, 164 insertions(+), 117 deletions(-) delete mode 100644 commands/add-money.js create mode 100644 commands/money.js delete mode 100644 commands/remove-money.js diff --git a/commands/add-money.js b/commands/add-money.js deleted file mode 100644 index c3156f8..0000000 --- a/commands/add-money.js +++ /dev/null @@ -1,88 +0,0 @@ -const { MessageEmbed } = require('discord.js'); - -module.exports = { - name: "add-money", - debug: false, - description: "change the starting balance for the server", - usage: "[user] [amount]", - permissions: { - channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], - member: ["MANAGE_GUILD"], - }, - SlashCommand: { - 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, - } - ], - /** - * - * @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.`); - } - - // send money from wallet - - let targetUserID = args[0].value.replace('<@!', '').replace('>', ''); - let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); - - if (!banking) { - banking = { - account: { - userID: targetUserID, - balance: GuildDB.startingBalance + args[1].value, - 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] }); - } - }); - } else { - let newBalance = banking.account.balance + args[1].value; - - client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newBalance}}, 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 added $${args[1].value.toFixed(2)} to <@${targetUserID}>'s balance`) - .setColor('GREEN'); - - return interaction.send({ embeds: [successEmbed] }); - }, - }, -} \ No newline at end of file diff --git a/commands/money.js b/commands/money.js new file mode 100644 index 0000000..b1b3d6d --- /dev/null +++ b/commands/money.js @@ -0,0 +1,164 @@ +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 give money", + 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.`); + } + + if (args[0].name == "add") { + // add money to user + + let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); + let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + + if (!banking) { + banking = { + account: { + userID: targetUserID, + balance: GuildDB.startingBalance + args[0].options[1].value, + 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] }); + } + }); + } else { + let newBalance = banking.account.balance + args[0].options[1].value; + + client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newBalance}}, 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() + .setDescription(`Successfully added $${args[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 targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); + let banking = await client.dbo.collection("banking").findOne({"account.userID": targetUserID}).then(banking => banking); + + if (!banking) { + banking = { + account: { + userID: targetUserID, + balance: GuildDB.startingBalance - args[0].options[1].value, + 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] }); + } + }); + } else { + let newBalance = banking.account.balance - args[0].options[1].value; + + client.dbo.collection("banking").updateOne({"account.userID":targetUserID},{$set:{"account.balance":newBalance}}, 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() + .setDescription(`Successfully removed $${args[1].value.toFixed(2)} from <@${targetUserID}>'s balance`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + } + }, + }, +} \ No newline at end of file diff --git a/commands/remove-money.js b/commands/remove-money.js deleted file mode 100644 index cb2d69a..0000000 --- a/commands/remove-money.js +++ /dev/null @@ -1,29 +0,0 @@ -const { MessageEmbed } = require('discord.js'); - -module.exports = { - name: "remove-money", - debug: false, - description: "remove money from a users balance or cash.", - usage: "", - permissions: { - channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], - member: [], - }, - SlashCommand: { - options: [], - /** - * - * @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.`); - } - - return interaction.send('debugging...') - }, - }, -} \ No newline at end of file