Skip to content

Commit

Permalink
Update item create and edit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Aug 7, 2024
1 parent 052693b commit 2f9e6aa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
36 changes: 28 additions & 8 deletions commands/Items/create-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down Expand Up @@ -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;
}
Expand All @@ -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],
Expand Down Expand Up @@ -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;
Expand All @@ -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,
},
]);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
},
]);
Expand Down Expand Up @@ -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;
Expand All @@ -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],
});

Expand Down
7 changes: 7 additions & 0 deletions commands/Items/edit-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 2f9e6aa

Please sign in to comment.