diff --git a/commands/Bot Support/global-blacklist.js b/commands/Bot Support/global-blacklist.js index 32215648..feb0406d 100644 --- a/commands/Bot Support/global-blacklist.js +++ b/commands/Bot Support/global-blacklist.js @@ -9,7 +9,8 @@ class GlobalBlacklist extends Command { name: 'global-blacklist', description: 'Blacklist someone from using the bot', usage: 'global-blacklist ', - requiredArgs: 1, + examples: ['global-blacklist check bunny', 'global-blacklist add bunny Being naughty'], + requiredArgs: 2, category: 'Bot Support', permLevel: 'Bot Support', aliases: ['gbl', 'g-blacklist', 'gblacklist'], @@ -26,6 +27,7 @@ class GlobalBlacklist extends Command { return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Incorrect Usage'); } else { type = args[0].toLowerCase(); + mem = await this.client.util.getMember(msg, args[1]); } } else if (args[0]) { // Check if the first argument is a user mention @@ -59,6 +61,7 @@ class GlobalBlacklist extends Command { if (!mem) { return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'User not found'); } + mem = mem.user ? mem.user : mem; args.shift(); args.shift(); @@ -66,6 +69,7 @@ class GlobalBlacklist extends Command { const blacklist = await db.get(`users.${mem.id}.blacklist`); + console.log(mem); const embed = new EmbedBuilder() .setAuthor({ name: mem.tag, iconURL: mem.displayAvatarURL() }) .setColor(msg.settings.embedColor) @@ -84,8 +88,8 @@ class GlobalBlacklist extends Command { await db.set(`users.${mem.id}.blacklistReason`, reason); embed.setTitle(`${mem.tag} has been added to the global blacklist.`).addFields([ - { name: 'Reason:', value: reason }, { name: 'User:', value: `${mem.tag} \n(${mem.id})` }, + { name: 'Reason:', value: reason }, ]); msg.channel.send({ embeds: [embed] }); @@ -105,8 +109,8 @@ class GlobalBlacklist extends Command { await db.set(`users.${mem.id}.blacklistReason`, reason); embed.setTitle(`${mem.tag} has been removed from the global blacklist.`).addFields([ - { name: 'Reason:', value: reason }, { name: 'User:', value: `${mem.tag} \n(${mem.id})` }, + { name: 'Reason:', value: reason }, ]); msg.channel.send({ embeds: [embed] }); @@ -117,13 +121,11 @@ class GlobalBlacklist extends Command { case 'check': { const reason = (await db.get(`users.${mem.id}.blacklistReason`)) || 'No reason specified'; - embed - .setTitle(`${mem.tag} blacklist check`) - .addFields([ - { name: 'User:', value: `${mem.tag} (${mem.id})`, inline: true }, - { name: 'Is Blacklisted?', value: blacklist ? 'True' : 'False', inline: true }, - ]) - .addField('Reason:', reason); + embed.setTitle(`${mem.tag} blacklist check`).addFields([ + { name: 'User:', value: `${mem.tag} (${mem.id})`, inline: true }, + { name: 'Is Blacklisted?', value: blacklist ? 'True' : 'False', inline: true }, + { name: 'Reason', value: reason, inline: true }, + ]); msg.channel.send({ embeds: [embed] }); break; diff --git a/commands/Items/buy-item.js b/commands/Items/buy-item.js index f7f322c8..132f0297 100644 --- a/commands/Items/buy-item.js +++ b/commands/Items/buy-item.js @@ -27,7 +27,6 @@ class BuyItem extends Command { // Find the item in the store regardless of case const itemKey = Object.keys(store).find((key) => key.toLowerCase() === itemName); - if (!itemKey) return msg.reply('That item does not exist in the store.'); const item = store[itemKey]; @@ -61,16 +60,15 @@ class BuyItem extends Command { userCash = userCash - itemCost; await db.set(`servers.${msg.guild.id}.users.${msg.member.id}.economy.cash`, userCash.toString()); - if (item.roleGiven) { - const role = this.client.util.getRole(msg, item.roleGiven); - await msg.member.roles.add(role).catch((error) => msg.channel.send(error)); - } - if (item.roleRemoved) { - const role = this.client.util.getRole(msg, item.roleRemoved); - await msg.member.roles.remove(role).catch((error) => msg.channel.send(error)); - } - if (!item.inventory) { + if (item.roleGiven) { + const role = this.client.util.getRole(msg, item.roleGiven); + await msg.member.roles.add(role).catch((error) => msg.channel.send(error)); + } + if (item.roleRemoved) { + const role = this.client.util.getRole(msg, item.roleRemoved); + await msg.member.roles.remove(role).catch((error) => msg.channel.send(error)); + } if (!item.replyMessage) { return msg.channel.send('👍'); } @@ -104,7 +102,6 @@ class BuyItem extends Command { (await this.client.util.getRole(msg, item.roleRemoved)) || (await this.client.util.getRole(msg, item.roleRequired)); - console.log(role); if (role) { const roleCreatedAt = moment(role.createdAt); const roleCreated = roleCreatedAt.format('D MM YY'); @@ -123,14 +120,19 @@ class BuyItem extends Command { const userInventory = (await db.get(`servers.${msg.guild.id}.users.${msg.member.id}.economy.inventory`)) || []; - // Check if the user already owns the item - const alreadyOwned = userInventory.find((inventoryItem) => inventoryItem.name.toLowerCase() === itemName); - if (alreadyOwned) return msg.reply('You already own this item.'); - - // Add the item to the user's inventory - userInventory.push({ name: itemKey, ...item }); - - await db.set(`servers.${msg.guild.id}.users.${msg.member.id}.economy.inventory`, userInventory); + // Find the index of the item in the user's inventory + const itemIndex = userInventory.findIndex((inventoryItem) => inventoryItem?.name?.toLowerCase() === itemName); + if (itemIndex !== -1) { + // If the item is found, increment the quantity + userInventory[itemIndex].quantity += 1; + await db.set(`servers.${msg.guild.id}.users.${msg.member.id}.economy.inventory`, userInventory); + } else { + // Add the item to the user's inventory + item.quantity = 1; + userInventory.push({ name: itemKey, ...item }); + + await db.set(`servers.${msg.guild.id}.users.${msg.member.id}.economy.inventory`, userInventory); + } const currencySymbol = (await db.get(`servers.${msg.guild.id}.economy.symbol`)) || '$'; const csCost = @@ -140,7 +142,9 @@ class BuyItem extends Command { const embed = new EmbedBuilder() .setTitle('Purchase Successful') - .setDescription(`You have successfully bought **${itemKey}** for ${csCost}.`) + .setDescription( + `You have bought ${itemKey} for ${csCost}! This is now in your inventory. \nUse this item with the \`use-item\` command.`, + ) .setColor(msg.settings.embedColor) .setTimestamp(); diff --git a/commands/Items/inventory.js b/commands/Items/inventory.js index 16fd56e8..54027460 100644 --- a/commands/Items/inventory.js +++ b/commands/Items/inventory.js @@ -42,9 +42,10 @@ class Inventory extends Command { const end = start + itemsPerPage; const paginatedInventory = userInventory.slice(start, end); + const currencySymbol = (await db.get(`servers.${msg.guild.id}.economy.symbol`)) || '$'; const inventoryDetails = paginatedInventory .map((item) => { - return `**${item?.name}** - ${BigInt(item?.cost || 0)?.toLocaleString()}\n${item?.description}`; + return `**${item?.quantity || 1} - ${item?.name}**\n${item?.description}`; }) .join('\n'); @@ -88,7 +89,7 @@ class Inventory extends Command { const newInventoryDetails = newPaginatedInventory .map((item) => { - return `**${item.name}** - ${BigInt(item.cost || 0)?.toLocaleString()}\n${item.description}`; + return `**${item?.quantity || 1} - ${item?.name}**\n${item?.description}`; }) .join('\n'); diff --git a/commands/Items/use-item.js b/commands/Items/use-item.js new file mode 100644 index 00000000..e0afbc95 --- /dev/null +++ b/commands/Items/use-item.js @@ -0,0 +1,104 @@ +const Command = require('../../base/Command.js'); +const { QuickDB } = require('quick.db'); +require('moment-duration-format'); +const moment = require('moment'); +const db = new QuickDB(); + +class UseItem extends Command { + constructor(client) { + super(client, { + name: 'use-item', + category: 'Items', + description: 'Use an item from your inventory.', + usage: 'use-item ', + aliases: ['useitem', 'use'], + guildOnly: true, + requiredArgs: 1, + }); + } + + async run(msg, args) { + const itemName = args.join(' ').toLowerCase(); + + // Fetch user's inventory from the database + const userInventory = (await db.get(`servers.${msg.guild.id}.users.${msg.author.id}.economy.inventory`)) || []; + + // Find the item in the store regardless of case + const itemIndex = userInventory.findIndex((inventoryItem) => inventoryItem?.name?.toLowerCase() === itemName); + + // Check if the item exists in the user's inventory + if (!userInventory[itemIndex]) { + return msg.reply('You do not have this item in your inventory.'); + } + + const item = userInventory[itemIndex]; + userInventory[itemIndex].quantity -= 1; + let filteredInventory; + + if (!item.quantity || item.quantity < 1) { + delete userInventory[itemIndex]; + // Remove null values + filteredInventory = await userInventory.filter((item) => item != null); + } + + await db.set(`servers.${msg.guild.id}.users.${msg.author.id}.economy.inventory`, filteredInventory); + + if (item.roleGiven) { + const role = this.client.util.getRole(msg, item.roleGiven); + await msg.member.roles.add(role).catch((error) => msg.channel.send(error)); + } + if (item.roleRemoved) { + const role = this.client.util.getRole(msg, item.roleRemoved); + await msg.member.roles.remove(role).catch((error) => msg.channel.send(error)); + } + if (!item.replyMessage) { + return msg.channel.send('👍'); + } + + // Replace Member + const memberCreatedAt = moment(msg.author.createdAt); + const memberCreated = memberCreatedAt.format('D MM YY'); + const memberCreatedDuration = memberCreatedAt.from(moment(), true); + let replyMessage = item.replyMessage + .replace('{member.id}', msg.author.id) + .replace('{member.username}', msg.author.username) + .replace('{member.tag}', msg.author.tag) + .replace('{member.mention}', msg.author) + .replace('{member.created}', memberCreated) + .replace('{member.created.duration}', memberCreatedDuration); + + // Replace Server + const guildCreatedAt = moment(msg.guild.createdAt); + const serverCreated = guildCreatedAt.format('D MM YY'); + const serverCreatedDuration = guildCreatedAt.from(moment(), true); + + replyMessage = replyMessage + .replace('{server.id}', msg.guild.id) + .replace('{server.name}', msg.guild.name) + .replace('{server.members}', msg.guild.memberCount.toLocaleString()) + .replace('{server.created}', serverCreated) + .replace('{servers.created.duration', serverCreatedDuration); + + const role = + (await this.client.util.getRole(msg, item.roleGiven)) || + (await this.client.util.getRole(msg, item.roleRemoved)) || + (await this.client.util.getRole(msg, item.roleRequired)); + + if (role) { + const roleCreatedAt = moment(role.createdAt); + const roleCreated = roleCreatedAt.format('D MM YY'); + const roleCreatedDuration = roleCreatedAt.from(moment(), true); + + replyMessage = replyMessage + .replace('{role.id}', role.id) + .replace('{role.name}', role.name) + .replace('{role.mention}', role) + .replace('{role.members}', role.members.size.toLocaleString()) + .replace('{role.created}', roleCreated) + .replace('{role.created.duration}', roleCreatedDuration); + } + return msg.channel.send(replyMessage); + } +} + +module.exports = UseItem;