From 2f9e6aad997f4e7c3f6505d6185c3451f7f646ad Mon Sep 17 00:00:00 2001 From: TheMonDon <11539895+TheMonDon@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:03:37 -0500 Subject: [PATCH] Update item create and edit --- commands/Items/create-item.js | 36 +++++++++++++++++++++++++++-------- commands/Items/edit-item.js | 7 +++++++ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/commands/Items/create-item.js b/commands/Items/create-item.js index 1bd8d51a..6940574e 100644 --- a/commands/Items/create-item.js +++ b/commands/Items/create-item.js @@ -21,6 +21,7 @@ class CreateItem extends Command { async run(msg, args) { const name = args.join(' ').slice(0, 200); const store = (await db.get(`servers.${msg.guild.id}.economy.store`)) || {}; + const botMember = msg.guild.members.cache.get(this.client.user.id); const filter = (m) => m.author.id === msg.author.id; const embed = new EmbedBuilder() .setAuthor({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL() }) @@ -83,7 +84,7 @@ class CreateItem extends Command { } else if (cost === Infinity) { await collected.first().reply(`The price must be less than ${BigInt(Number.MAX_VALUE).toLocaleString()}.`); } else if (cost < 0) { - await msg.reply('The price must be at least zero. Please enter a valid cost.'); + await collected.first().reply('The price must be at least zero. Please enter a valid cost.'); } else { isValid = true; } @@ -93,6 +94,7 @@ class CreateItem extends Command { const costString = currencySymbol + cost.toLocaleString(); const limitedCostString = costString.length > 1024 ? costString.slice(0, 1020) + '...' : costString; embed.addFields([{ name: 'Price', value: limitedCostString, inline: true }]); + await message.edit({ content: '2️⃣ What would you like the description to be? \nThis should be no more than 1000 characters', embeds: [embed], @@ -250,7 +252,9 @@ class CreateItem extends Command { roleRequired = this.client.util.getRole(msg, collected.first().content); if (!roleRequired) { - collected.first().reply('Please reply with a valid server role.'); + collected + .first() + .reply('Please reply with a valid server role. Try again or use `cancel` to cancel the command'); } else { roleRequired = roleRequired.id; isValid = true; @@ -259,7 +263,7 @@ class CreateItem extends Command { embed.addFields([ { name: 'Role Required', - value: roleRequired ? this.client.util.getRole(msg, roleRequired)?.toString() : 'None', + value: roleRequired ? this.client.util.getRole(msg, roleRequired).toString() : 'None', inline: true, }, ]); @@ -299,7 +303,15 @@ class CreateItem extends Command { roleGiven = this.client.util.getRole(msg, collected.first().content); if (!roleGiven) { - collected.first().reply('Please reply with a valid server role.'); + collected + .first() + .reply('Please reply with a valid server role. Try again or use `cancel` to cancel the command'); + } else if (roleGiven.position >= botMember.roles.highest.position) { + collected + .first() + .reply( + "The role you mentioned is above or equal to the bot's highest role. Please try again with a different role or use `cancel` to cancel the command", + ); } else { roleGiven = roleGiven.id; isValid = true; @@ -308,7 +320,7 @@ class CreateItem extends Command { embed.addFields([ { name: 'Role Given', - value: roleGiven ? this.client.util.getRole(msg, roleGiven)?.toString() : 'None', + value: roleGiven ? this.client.util.getRole(msg, roleGiven).toString() : 'None', inline: true, }, ]); @@ -348,7 +360,15 @@ class CreateItem extends Command { roleRemoved = this.client.util.getRole(msg, collected.first().content); if (!roleRemoved) { - collected.first().reply('Please reply with a valid server role.'); + collected + .first() + .reply('Please reply with a valid server role. Try again or use `cancel` to cancel the command'); + } else if (roleRemoved.position >= botMember.roles.highest.position) { + collected + .first() + .reply( + "The role you mentioned is above or equal to the bot's highest role. Please try again with a different role or use `cancel` to cancel the command", + ); } else { roleRemoved = roleRemoved.id; isValid = true; @@ -357,14 +377,14 @@ class CreateItem extends Command { embed.addFields([ { name: 'Role Removed', - value: roleRemoved ? this.client.util.getRole(msg, roleRemoved)?.toString() : 'None', + value: roleRemoved ? this.client.util.getRole(msg, roleRemoved).toString() : 'None', inline: true, }, ]); await message.edit({ content: - '8️⃣ What message do you want the bot to reply with, when the item is bought (or used if an inventory item)? \nYou can use the Member, Server & Role tags from https://unbelievaboat.com/tags in this message. \nThis should be no more than 1000 characters \nIf none, just reply `skip`.', + '8️⃣ What message do you want the bot to reply with, when the item is bought (or used if an inventory item)? \nYou can use the Member, Server & Role tags from https://mythical.cisn.xyz/tags in this message. \nThis should be no more than 1000 characters \nIf none, just reply `skip`.', embeds: [embed], }); diff --git a/commands/Items/edit-item.js b/commands/Items/edit-item.js index b6db4e05..d7cfa77a 100644 --- a/commands/Items/edit-item.js +++ b/commands/Items/edit-item.js @@ -23,6 +23,7 @@ class EditItem extends Command { async run(msg, args) { const attribute = args.shift().toLowerCase(); + const botMember = msg.guild.members.cache.get(this.client.user.id); let itemName; let newValue; const errorEmbed = new EmbedBuilder() @@ -158,6 +159,9 @@ class EditItem extends Command { if (!role) { errorEmbed.setDescription('Please re-run the command with a valid role.'); return msg.channel.send({ embeds: [errorEmbed] }); + } else if (role.position >= botMember.roles.highest.position) { + errorEmbed.setDescription('I am not able to assign this role. Please move my role higher.'); + return msg.channel.send({ embeds: [errorEmbed] }); } item.roleGiven = role.id; store[itemKey] = item; @@ -174,6 +178,9 @@ class EditItem extends Command { if (!role) { errorEmbed.setDescription('Please re-run the command with a valid role.'); return msg.channel.send({ embeds: [errorEmbed] }); + } else if (role.position >= botMember.roles.highest.position) { + errorEmbed.setDescription('I am not able to assign this role. Please move my role higher.'); + return msg.channel.send({ embeds: [errorEmbed] }); } item.roleRemoved = role.id; store[itemKey] = item;