diff --git a/commands/inventory.js b/commands/inventory.js index ecb1781..6676f19 100644 --- a/commands/inventory.js +++ b/commands/inventory.js @@ -1,4 +1,4 @@ -const { MessageEmbed } = require('discord.js'); +const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); const Inventory = require('../structures/inventory'); const action = ['ditch', 'drop', 'forget', 'throw out', 'leave', 'set down', 'let go of']; @@ -78,6 +78,12 @@ module.exports = { } ], }, + { + name: "clear", + description: "clear your inventory", + value: "clear", + type: 1, + } ], /** * @@ -306,6 +312,59 @@ module.exports = { .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); + + } else if (args[0].name == 'clear') { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to clear your inventory?`) + .setDescription('**Note:** This will not affect your wallet.') + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt] }); + + client.on("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", + ephemeral: true + }) + } + let action = '' + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'cleared'; + const tempWallet = inventory.items[0]; + client.dbo.collection("inventories").updateOne({"inventory.userID":inventory.userID},{$set:{"inventory.items": [tempWallet]}},function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} your inventory.`) + + return ButtonInteraction.update({ embeds: [successEmbed], components: [] }); + }); + return; } }, }, diff --git a/commands/settings.js b/commands/settings.js index 97814c1..23f108b 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -1,4 +1,4 @@ -const { MessageEmbed, Guild } = require('discord.js'); +const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); module.exports = { name: "settings", @@ -211,21 +211,28 @@ module.exports = { const opt = new MessageActionRow() .addComponents( new MessageButton() - .setCustomId(`yes`) + .setCustomId(`yes-${interaction.member.user.id}`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() - .setCustomId(`no`) + .setCustomId(`no-${interaction.member.user.id}`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); - client.once("interactionCreate", ButtonInteraction => { + client.on("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", + ephemeral: true + }) + } let action = '' - if (queryString=='yes') { + if (queryString==`yes-${interaction.member.user.id}`) { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, function (err, res) { if (err) { @@ -237,7 +244,7 @@ module.exports = { return interaction.send({ embeds: [embed] }); } }); - } else if (queryString=='no') action = 'kept'; + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") @@ -284,21 +291,28 @@ module.exports = { const opt = new MessageActionRow() .addComponents( new MessageButton() - .setCustomId(`yes`) + .setCustomId(`yes-${interaction.member.user.id}`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() - .setCustomId(`no`) + .setCustomId(`no-${interaction.member.user.id}`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); - client.once("interactionCreate", ButtonInteraction => { + client.on("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", + ephemeral: true + }) + } let action = '' - if (queryString=='yes') { + if (queryString==`yes-${interaction.member.user.id}`) { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":ButtonInteraction.guild.id},{$set:{"server.actionChannel": null}},function(err, res) { if (err) { @@ -310,7 +324,7 @@ module.exports = { return interaction.send({ embeds: [embed] }); } }); - } else if (queryString=='no') action = 'kept'; + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") @@ -357,21 +371,28 @@ module.exports = { const opt = new MessageActionRow() .addComponents( new MessageButton() - .setCustomId(`yes`) + .setCustomId(`yes-${interaction.member.user.id}`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() - .setCustomId(`no`) + .setCustomId(`no-${interaction.member.user.id}`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); - client.once("interactionCreate", ButtonInteraction => { + client.on("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", + ephemeral: true + }) + } let action = '' - if (queryString=='yes') { + if (queryString==`yes-${interaction.member.user.id}`) { action = 'removed'; client.dbo.collection("guilds").updateOne({"server.serverID":ButtonInteraction.guild.id},{$set:{"server.tweetChannel": null}},function(err, res) { if (err) { @@ -383,7 +404,7 @@ module.exports = { return interaction.send({ embeds: [embed] }); } }); - } else if (queryString=='no') action = 'kept'; + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") @@ -411,13 +432,14 @@ module.exports = { .setDescription(`Successfully set $${args[0].options[0].value.toFixed(2)} as starting balance`); return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].name == 'set_income_role') { if (args[0].options[1].value <= 0) { let embed = new MessageEmbed() - .setDescriptions('**Error Notice:** Amount cannot be $0 or less than $0.') - .setColor("RED"); + .setDescriptions('**Error Notice:** Amount cannot be $0 or less than $0.') + .setColor("RED"); - return interaction.send({ embeds: [embed] }); + return interaction.send({ embeds: [embed] }); } const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[0].value);