map and move interaction handlers

This commit is contained in:
SowinskiBraeden committed 2022-10-14 10:13:56 -07:00
1 parent 8850d02211
commit 19f41b5f2a
9 files changed
+622 -584

No files matched your search

+178 -5
View File
@@ -2,6 +2,7 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuBu
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",
@@ -191,7 +192,7 @@ module.exports = {
if (args[0].name == 'view') {
let items = new SelectMenuBuilder()
.setCustomId(`inventorySelect-${interaction.member.user.id}`)
.setCustomId(`InventoryView-${interaction.member.user.id}`)
.setPlaceholder('Select Item to view')
.addOptions(
{
@@ -292,7 +293,7 @@ module.exports = {
}
let items = new SelectMenuBuilder()
.setCustomId(`dropSelect-${interaction.member.user.id}`)
.setCustomId(`InventoryDrop-${interaction.member.user.id}`)
.setPlaceholder('Select item to drop')
for (let i = 1; i < inventory.guilds[GuildDB.serverID].items.length; i++) {
@@ -327,7 +328,7 @@ module.exports = {
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
let items = new SelectMenuBuilder()
.setCustomId(`giveSelect-${targetUserID}-${interaction.member.user.id}`)
.setCustomId(`InventoryGive-${targetUserID}-${interaction.member.user.id}`)
.setPlaceholder('Select Item to give')
for (let i = 1; i < inventory.guilds[GuildDB.serverID].items.length; i++) {
@@ -359,11 +360,11 @@ module.exports = {
const opt = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId(`inventoryClear-yes-${interaction.member.user.id}`)
.setCustomId(`InventoryClear-yes-${interaction.member.user.id}`)
.setLabel("Yes")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId(`inventoryClear-no-${interaction.member.user.id}`)
.setCustomId(`InventoryClear-no-${interaction.member.user.id}`)
.setLabel("No")
.setStyle(ButtonStyle.Success)
)
@@ -373,4 +374,176 @@ module.exports = {
}
},
},
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 = `${client.exists(item.ID.firstname) ? item.ID.firstname : '...'} ${client.exists(item.ID.lastname) ? item.ID.lastname : '...'} | ${client.exists(item.ID.dob) ? item.ID.dob : 'N/A'} | ${client.exists(item.ID.addr) ? item.ID.addr : 'N/A'}`
itemEmbed.setTitle(`Your Wallet`);
itemEmbed.addFields(
{ name: '**Cash**', value: `$${item.cash.toFixed(2)}`, inline: true },
{ name: '**ID**', value: ID, inline: true });
} 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[args[0].options[0].value-1];
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(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[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(err);
});
} else {
targetUserInventory = targetUserIventory.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(err);
});
client.dbo.collection('inventories').updateOne({'inventory.userID': targetUserID}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) {
if (err) return client.sendInternalError(err);
});
}
let successEmbed = new EmbedBuilder()
.setTitle('Success')
.setDescription(`Successfully gave <@${targetUserID}> ${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(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: [] });
}
}
}
}