reset cmd/improve money cmd/fix settings cmd options

This commit is contained in:
SowinskiBraeden committed 2022-08-26 14:11:48 -07:00
1 parent 9bcfad7963
commit 63ceb3de84
5 files changed
+200 -126

No files matched your search

+1 -1
View File
@@ -540,7 +540,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
+40 -85
View File
@@ -12,51 +12,30 @@ module.exports = {
}, },
options: [ options: [
{ {
name: "add", name: "add_or_remove",
description: "Add money to user", description: "Add or remove money from a user",
value: "add", value: "add_or_remove",
type: 1, type: 3,
options: [ required: true,
{ choices: [
name: "user", { name: "add", value: "add" }, { name: "remove", value: "remove" },
description: "User to give money", ]
value: "user",
type: 6,
required: true,
},
{
name: "amount",
description: "The amount to add to balance",
value: "amount",
type: 5,
min_value: 0.01,
required: true,
}
],
}, },
{ {
name: "remove", name: "amount",
description: "Remove money from user", description: "The amount to add to balance",
value: "remove", value: "amount",
type: 1, type: 5,
options: [ min_value: 0.01,
{ required: true,
name: "user", },
description: "User to remove money from", {
value: "user", name: "from",
type: 6, description: "User to alter balance",
required: true, value: "from",
}, type: 6,
{ required: true,
name: "amount", },
description: "The amount to add to balance",
value: "amount",
type: 5,
min_value: 0.01,
required: true,
}
],
}
], ],
SlashCommand: { SlashCommand: {
/** /**
@@ -78,7 +57,7 @@ module.exports = {
if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) 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.'); if (!canUseCommand) return interaction.send('You don\'t have the permissions to use this command.');
let targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); const targetUserID = args[2].value.replace('<@!', '').replace('>', '');
let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking);
if (!banking) { if (!banking) {
@@ -122,51 +101,27 @@ module.exports = {
return interaction.send({ embeds: [embed] }); return interaction.send({ embeds: [embed] });
} }
} }
if (args[0].name == "add") { const newBalance = args[0] == 'add'
// add money to user ? banking.guilds[GuildDB.serverID].account.balance + args[1].value
: banking.guilds[GuildDB.serverID].account.balance - args[1].value;
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) { client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance}}, function(err, res) {
if (err) { if (err) {
client.log(err); client.log(err);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red) .setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
let successEmbed = new EmbedBuilder() return interaction.send({ embeds: [embed] });
.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) { const successEmbed = new EmbedBuilder()
if (err) { .setDescription(`Successfully ${args[0] == 'add' ? 'added' : 'removed'} $${args[0].options[1].value.toFixed(2)} ${args[0] == 'add' ? 'to' : 'from'} <@${targetUserID}>'s balance`)
client.log(err); .setColor('GREEN');
const embed = new EmbedBuilder()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return interaction.send({ embeds: [embed] });
}
});
let successEmbed = new EmbedBuilder()
.setDescription(`Successfully removed $${args[0].options[1].value.toFixed(2)} from <@${targetUserID}>'s balance`)
.setColor('GREEN');
return interaction.send({ embeds: [successEmbed] }); return interaction.send({ embeds: [successEmbed] });
}
}, },
}, },
} }
+125
View File
@@ -0,0 +1,125 @@
const { EmbedBuilder } = require('discord.js');
const { addInventory } = require('../structures/inventory');
const { addBank } = require('../structures/bank');
module.exports = {
name: "",
debug: false,
description: "",
usage: "",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
options: [{
name: "user",
description: "User to reset",
value: "user",
type: 6,
required: true,
}],
SlashCommand: {
/**
*
* @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.');
const targetUserID = args[0].value.replace('<@!', '').replace('>', '');
const prompt = new EmbedBuilder()
.setTitle(`Are you sure you want to reset this user?`)
.setDescription('**Notice:** This will reset this users, cash, balance, and invnetory back to defaults.')
.setColor(client.config.Colors.Yellow)
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
return ButtonInteraction.reply({
content: "This button is not for you",
flags: (1 << 6)
})
}
if (queryString==`yes-${interaction.member.user.id}`) {
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setTitle('Successfully reset user\'s data')
let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory);
let banking = await client.dbo.collection("banks").findOne({"account.userID": interaction.member.user.id}).then(banking => banking);
let inventoryReset = false;
let bankingReset = false;
if (!inventory) inventoryReset = true
else inventory = inventory.inventory
if (!banking) bankingReset = true
else banking = banking.banking
if (inventoryReset && bankingReset) return ButtonInteraction.update({ embeds: [successEmbed], components: [] });
if (!inventoryReset) {
const success = addInventory(inventory.guilds, GuildDB.serverID, targetUserID, client);
if (!success) {
client.log(err);
const embed = new EmbedBuilder()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return ButtonInteraction.update({ embeds: [embed], components: [] });
}
}
if (!bankingReset) {
const success = addBank(banking.guilds, GuildDB.serverID, targetUserID, client);
if (!success) {
client.log(err);
const embed = new EmbedBuilder()
.setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`)
.setColor(client.config.Colors.Red)
return ButtonInteraction.update({ embeds: [embed], components: [] });
}
}
return ButtonInteraction.update({ embeds: [successEmbed], components: [] });
} else if (queryString==`no-${interaction.member.user.id}`) {
const successEmbed = new EmbedBuilder()
.setColor(client.config.Colors.Green)
.setTitle(`The User was not reset`);
return ButtonInteraction.update({ embeds: [successEmbed], components: [] });
}
});
return;
},
},
}
+10 -10
View File
@@ -413,7 +413,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -491,7 +491,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -569,7 +569,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -647,7 +647,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -726,7 +726,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -854,7 +854,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -928,7 +928,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -1002,7 +1002,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -1076,7 +1076,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
@@ -1150,7 +1150,7 @@ module.exports = {
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
client.on("interactionCreate", ButtonInteraction => { client.once("interactionCreate", ButtonInteraction => {
if(!ButtonInteraction.isButton()) return; if(!ButtonInteraction.isButton()) return;
const queryString = ButtonInteraction.customId; const queryString = ButtonInteraction.customId;
if (!queryString.endsWith(ButtonInteraction.member.user.id)) { if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
+24 -30
View File
@@ -1,5 +1,21 @@
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const defaultGuildData = {
items: [{
name: 'Wallet',
type: 'wallet',
description: '`/wallet view` to view wallet',
cash: 0.00,
ID: {
firstname: '',
lastname: '',
dob: '',
addr: '',
}
}],
lastWork: new Date('2000-01-01T00:00:00') // garantee's they can work right after inventory create,
}
let inventorySchema = mongoose.Schema({ let inventorySchema = mongoose.Schema({
inventory: { inventory: {
userID: String, userID: String,
@@ -9,45 +25,23 @@ let inventorySchema = mongoose.Schema({
inventorySchema.methods.createInventory = function (userID, guildID) { inventorySchema.methods.createInventory = function (userID, guildID) {
this.inventory.userID = userID; this.inventory.userID = userID;
const newGuild = {
items: [{
name: 'Wallet',
type: 'wallet',
description: '`/wallet view` to view wallet',
cash: 0.00,
ID: {
firstname: '',
lastname: '',
dob: ''
}
}],
lastWork: new Date('2000-01-01T00:00:00') // garantee's they can work right after inventory create,
};
this.inventory.guilds = {}; this.inventory.guilds = {};
this.inventory.guilds[guildID] = newGuild this.inventory.guilds[guildID] = defaultGuildData;
}; };
inventorySchema.methods.addItem = function (guildID, item) { inventorySchema.methods.addItem = function (guildID, item) {
this.inventory.guilds[guildID].items.push(item); this.inventory.guilds[guildID].items.push(item);
}; };
// This function is to add a new guild specific inventory to an already existing /*
// inventory document This function is to add a new guild specific inventory to an already existing
inventory document
or
can be used to reset a data back to default
*/
function addInventory(guilds, guildID, userID, client) { function addInventory(guilds, guildID, userID, client) {
let updatedGuilds = guilds; let updatedGuilds = guilds;
updatedGuilds[guildID] = { updatedGuilds[guildID] = defaultGuildData;
items: [{
name: 'Wallet',
type: 'wallet',
description: '`/wallet view` to view wallet',
cash: 0.00,
ID: {
firstname: '',
lastname: '',
dob: ''
}
}],
}
client.dbo.collection("inventories").updateOne({"inventory.userID":userID}, {$set: {"inventory.guilds": updatedGuilds}}, function(err, res) { client.dbo.collection("inventories").updateOne({"inventory.userID":userID}, {$set: {"inventory.guilds": updatedGuilds}}, function(err, res) {
if (err) return false if (err) return false