const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuBuilder } = require('discord.js'); const { Inventory, addInventory } = require('../structures/inventory'); const getActions = ['pick up', 'grab', 'get', 'aquire', 'obtain', 'gain', 'take possesssion of', 'retrieve']; const dropActions = ['ditch', 'drop', 'forget', 'throw out', 'leave', 'set down', 'let go of', 'discard']; module.exports = { name: "inventory", debug: false, global: false, description: "Manage your inventory", usage: "[command]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, options: [ { name: "view", description: "View your inventory", value: "view", type: 1, }, { name: "wallet", description: "View your wallet", value: "wallet", type: 1, }, { name: "add", description: "Add item to inventory", value: "add", type: 2, options: [ { name: "firearm", description: "Add firearm to inventory", value: "firearm", type: 1, options: [ { name: "type", description: "Type of firearm", value: "type", type: 3, required: true, choices: [ { name: 'Pistol', value: 'Pistol' }, { name: 'Revolver', value: 'Revolver' }, { name: 'Shotgun', value: 'Shotgun' }, { name: 'Submachine Gun', value: 'Submachine Gun' }, { name: 'Light Machine Gun', value: 'Ligh Machine Gun' }, { name: 'Assault Rifle', value: 'Assault Rifle' }, { name: 'Sniper Rifle', value: 'Sniper Rifle' }, ] }, { name: "serialnumber", description: "Firearm serial number", value: "serialnumber", type: 3, required: true, }, { name: "owner", description: "Firearm Owner's Full Name", value: "owner", type: 3, required: true, }, { name: "description", description: "Firearm description", value: "description", type: 3, required: true, } ] }, { name: "generic", description: "Add a generic item to inventory", value: "generic", type: 1, options: [ { name: "name", description: "Item name", value: "name", type: 3, required: true, }, { name: "description", description: "Item description", value: "description", type: 3, required: true, }, { name: "quantity", description: "The number of this item", value: "quantity", type: 4, required: true, } ] } ] }, { name: "give", description: "Give user item from inventory", value: "give", type: 1, options: [ { name: "user", description: "User to give item", value: "user", type: 6, required: true, } ], }, { name: "drop", description: "Drop item from inventory", value: "drop", type: 1, }, { name: "clear", description: "Clear your inventory", value: "clear", type: 1, } ], SlashCommand: { /** * * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").Message} 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({ content: `You are not allowed to use the bot in this channel.` }); } let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory); if (!inventory) { inventory = { userID: interaction.member.user.id, guilds: { [GuildDB.serverID]: { items: [{ name: 'Wallet', type: 'wallet', description: '`/inventory wallet` to view wallet', cash: 0.00, ID: { firstname: '', lastname: '', dob: '' } }] } } } // Register inventory for user let newInventory = new Inventory(); newInventory.createInventory(interaction.member.user.id, GuildDB.serverID); newInventory.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); } else inventory = inventory.inventory if (!client.exists(inventory.guilds[GuildDB.serverID])) { const success = addInventory(inventory.guilds, GuildDB.serverID, interaction.member.user.id, client); if (!success) return client.sendInternalError(interaction, 'Failed to add inventory'); } if (args[0].name == 'view') { let items = new SelectMenuBuilder() .setCustomId(`InventoryView-${interaction.member.user.id}`) .setPlaceholder('Select Item to view') .addOptions( { label: 'View All', description: 'View a list of all your inventory items', value: 'all', } ) for (let i = 0; i < inventory.guilds[GuildDB.serverID].items.length; i++) { if (inventory.guilds[GuildDB.serverID].items[i].type == 'firearm') { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].weaponType, description: 'View this items description', value: `${i}` }) } else { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].name, description: 'View this items description', value: `${i}` }) } } const opt = new ActionRowBuilder().addComponents(items); interaction.send({ components: [opt], flags: (1 << 6) }) } else if (args[0].name == 'wallet') { // Display wallet let item = inventory.guilds[GuildDB.serverID].items[0]; let ID = `**FN** ${client.exists(item.ID.firstname) ? `${item.ID.firstname}` : '...'} **LN** ${client.exists(item.ID.lastname) ? item.ID.lastname : '...'} **DOB** ${client.exists(item.ID.dob) ? item.ID.dob : 'N/A'}\n**Address** ${client.exists(item.ID.addr) ? item.ID.addr : 'N/A'} **Height** ${client.exists(item.ID.height) ? item.ID.height : 'N/A'} **Weight** ${client.exists(item.ID.weight) ? item.ID.weight : 'N/A'}\n**Eye Color** ${client.exists(item.ID.eyeColor) ? item.ID.eyeColor : 'N/A'} **Hair Color** ${client.exists(item.ID.hairColor) ? item.ID.hairColor : 'N/A'} **Sex** ${client.exists(item.ID.sex) ? item.ID.sex : 'N/A'}` let walletEmbed = new EmbedBuilder() .setTitle(`Your Wallet`) .setColor(client.config.Colors.Default) .addFields( { name: '**Cash**', value: `$${item.cash.toFixed(2)}`, inline: true }, { name: '**ID**', value: ID, inline: false }); return interaction.send({ embeds: [walletEmbed] }); } else if (args[0].name == 'add') { if (args[0].options[0].name == 'firearm') { // Add firearm to inventory const firearm = { type: 'firearm', weaponType: args[0].options[0].options[0].value, serial: args[0].options[0].options[1].value, ownerName: args[0].options[0].options[2].value, description: args[0].options[0].options[3].value, quantity: 1, } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: firearm}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); }); let message = new EmbedBuilder() .setTitle(`You ${getActions[Math.floor(Math.random() * getActions.length)]} a ${firearm.weaponType}`) .setColor(client.config.Colors.Default); return interaction.send({ embeds: [message] }); } else { // Add generic item to inventory const item = { type: 'generic', name: args[0].options[0].options[0].value, description: args[0].options[0].options[1].value, quantity: args[0].options[0].options[2].value, } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); }); let message = new EmbedBuilder() .setTitle(`You ${getActions[Math.floor(Math.random() * getActions.length)]} a ${item.name}`) .setColor(client.config.Colors.Default); return interaction.send({ embeds: [message] }); } } else if (args[0].name == 'drop') { // Remove Item from inventory if (inventory.guilds[GuildDB.serverID].items.length == 1) { const nsi = new EmbedBuilder() .setDescription('**Notice:** No items to drop') .setColor(client.config.Colors.Yellow); return interaction.send({ embeds: [nsi] }); } let items = new SelectMenuBuilder() .setCustomId(`InventoryDrop-${interaction.member.user.id}`) .setPlaceholder('Select item to drop') for (let i = 1; i < inventory.guilds[GuildDB.serverID].items.length; i++) { if (inventory.guilds[GuildDB.serverID].items[i].type == 'firearm') { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].weaponType, description: 'Drop this item', value: `${i}` }) } else { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].name, description: 'Drop this item', value: `${i}` }) } } const opt = new ActionRowBuilder().addComponents(items); interaction.send({ components: [opt], flags: (1 << 6) }) } else if (args[0].name == 'give') { if (inventory.guilds[GuildDB.serverID].items.length == 1) { const nsi = new EmbedBuilder() .setDescription('**Notice:** No items to give') .setColor(client.config.Colors.Yellow); return interaction.send({ embeds: [nsi] }); } const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', ''); let items = new SelectMenuBuilder() .setCustomId(`InventoryGive-${targetUserID}-${interaction.member.user.id}`) .setPlaceholder('Select Item to give') for (let i = 1; i < inventory.guilds[GuildDB.serverID].items.length; i++) { if (inventory.guilds[GuildDB.serverID].items[i].type == 'firearm') { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].weaponType, description: 'Give this item', value: `${i}` }) } else { items.addOptions({ label: inventory.guilds[GuildDB.serverID].items[i].name, description: 'Give this item', value: `${i}` }) } } const opt = new ActionRowBuilder().addComponents(items); interaction.send({ components: [opt], flags: (1 << 6) }) } else if (args[0].name == 'clear') { const prompt = new EmbedBuilder() .setTitle(`Are you sure you want to clear your inventory?`) .setDescription('**Note:** This will not affect your wallet.') .setColor(client.config.Colors.Default) const opt = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId(`InventoryClear-yes-${interaction.member.user.id}`) .setLabel("Yes") .setStyle(ButtonStyle.Danger), new ButtonBuilder() .setCustomId(`InventoryClear-no-${interaction.member.user.id}`) .setLabel("No") .setStyle(ButtonStyle.Success) ) return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) }); } }, }, Interactions: { InventoryView: { run: async (client, interaction, GuildDB) => { if (!interaction.customId.endsWith(interaction.member.user.id)) { return interaction.reply({ content: "This button is not for you", flags: (1 << 6) }) } let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory); inventory = inventory.inventory; if (interaction.values[0] == 'all') { let inventoryEmbed = new EmbedBuilder() .setColor(client.config.Colors.Default) .setTitle('Your Inventory') let description = `To see detials on an Item use \`/inventory view\` and select the item to view\n\n\`\`\`` for (let i = 0; i < inventory.guilds[GuildDB.serverID].items.length; i++) { if (inventory.guilds[GuildDB.serverID].items[i].type == 'firearm') description += `${i+1}. ${inventory.guilds[GuildDB.serverID].items[i].weaponType} - ${inventory.guilds[GuildDB.serverID].items[i].description}\n`; else description += `${i+1}. ${inventory.guilds[GuildDB.serverID].items[i].name} - ${inventory.guilds[GuildDB.serverID].items[i].description}\n` } description += "```" inventoryEmbed.setDescription(description); return interaction.update({ embeds: [inventoryEmbed], components: [], flags: (1 << 6) }); } else { let item = inventory.guilds[GuildDB.serverID].items[interaction.values[0]]; let itemEmbed = new EmbedBuilder().setColor(client.config.Colors.Default); if (item.type == 'wallet') { // Display wallet let ID = `**FN** ${client.exists(item.ID.firstname) ? `${item.ID.firstname}` : '...'} **LN** ${client.exists(item.ID.lastname) ? item.ID.lastname : '...'} **DOB** ${client.exists(item.ID.dob) ? item.ID.dob : 'N/A'}\n**Address** ${client.exists(item.ID.addr) ? item.ID.addr : 'N/A'} **Height** ${client.exists(item.ID.height) ? item.ID.height : 'N/A'} **Weight** ${client.exists(item.ID.weight) ? item.ID.weight : 'N/A'}\n**Eye Color** ${client.exists(item.ID.eyeColor) ? item.ID.eyeColor : 'N/A'} **Hair Color** ${client.exists(item.ID.hairColor) ? item.ID.hairColor : 'N/A'} **Sex** ${client.exists(item.ID.sex) ? item.ID.sex : 'N/A'}` itemEmbed.setTitle(`Your Wallet`); itemEmbed.addFields( { name: '**Cash**', value: `$${item.cash.toFixed(2)}`, inline: true }, { name: '**ID**', value: ID, inline: false }); } else if (item.type == 'firearm') { // Display firearm itemEmbed.setTitle('Firearm'); itemEmbed.addFields( { name: 'Serial #', value: item.serial, inline: true }, { name: 'Type', value: item.weaponType, inline: true }, { name: 'Description', value: item.description, inline: true }, { name: 'Owner', value: item.ownerName, inline: true } ); } else { // Display generic item here itemEmbed.setTitle(`Item information`); itemEmbed.addFields({ name: item.name, value: item.description, inline: false }); } return interaction.update({ embeds: [itemEmbed], components: [], flags: (1 << 6) }); } } }, InventoryDrop: { run: async (client, interaction, GuildDB) => { if (!interaction.customId.endsWith(interaction.member.user.id)) { return interaction.reply({ content: "This button is not for you", flags: (1 << 6) }) } let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory); inventory = inventory.inventory; let item = inventory.guilds[GuildDB.serverID].items[parseInt(interaction.values[0])]; client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$pull: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); let message = new EmbedBuilder() .setTitle(`You ${dropActions[Math.floor(Math.random() * dropActions.length)]} your ${item.name}`) .setColor(client.config.Colors.Default); return interaction.update({ embeds: [message], components: [] }); }); } }, InventoryGive: { run: async (client, interaction, GuildDB) => { if (!interaction.customId.endsWith(interaction.member.user.id)) { return interaction.reply({ content: "This button is not for you", flags: (1 << 6) }) } let inventory = await client.dbo.collection("inventories").findOne({"inventory.userID": interaction.member.user.id}).then(inventory => inventory); inventory = inventory.inventory; let item = inventory.guilds[GuildDB.serverID].items[parseInt(interaction.values[0])]; let targetUserID = interaction.customId.split('-')[1].replace('<@!', '').replace('>', ''); let targetUserInventory = await client.dbo.collection("inventories").findOne({"inventory.userID":targetUserID}).then(inventory => inventory); if (!targetUserInventory) { // Register inventory for user with item givn let newInventory = new Inventory(); newInventory.createInventory(targetUserID, GuildDB.serverID); newInventory.addItem(item); newInventory.save().catch(err => { if (err) return client.sendInternalError(interaction, err); }); } else { targetUserInventory = targetUserInventory.inventory; if (!client.exists(targetUserInventory.guilds[GuildDB.serverID])) { const success = addInventory(inventory.guilds, GuildDB.serverID, targetUserID, client); if (!success) { client.error(err); const embed = new EmbedBuilder() .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setColor(client.config.Colors.Red) return interaction.update({ embeds: [embed], components: [] }); } } client.dbo.collection('inventories').updateOne({'inventory.userID': interaction.member.user.id}, {$pull: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); }); client.dbo.collection('inventories').updateOne({'inventory.userID': targetUserID}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); }); } let successEmbed = new EmbedBuilder() .setTitle('Success') .setDescription(`Successfully gave <@${targetUserID}> ${item.type == 'fireamm' ? item.weaponType : item.name}`) .setColor(client.config.Colors.Green); return interaction.update({ embeds: [successEmbed], components: [] }); } }, InventoryClear: { run: async (client, interaction, GuildDB) => { const queryString = interaction.customId; if (!queryString.endsWith(interaction.member.user.id)) { return interaction.reply({ content: "This button is not for you", flags: (1 << 6) }) } let action = '' if (queryString==`inventoryClear-yes-${interaction.member.user.id}`) { action = 'cleared'; const tempWallet = inventory.guilds[GuildDB.serverID].items[0]; client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id},{$set:{[`inventory.guilds.${GuildDB.serverID}.items`]: [tempWallet]}},function(err, res) { if (err) return client.sendInternalError(interaction, err); }); } else if (queryString==`inventoryClear-no-${interaction.member.user.id}`) action = 'kept'; const successEmbed = new EmbedBuilder() .setColor(client.config.Colors.Green) .setTitle(`Successfully ${action} your inventory.`) return interaction.update({ embeds: [successEmbed], components: [] }); } } } }