debug button/menu interactions
This commit is contained in:
12 files changed
+844
-834
No files matched your search
+39
-213
@@ -1,7 +1,7 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, SelectMenuBuilder } = require('discord.js');
|
||||
const { Inventory, addInventory } = require('../structures/inventory');
|
||||
|
||||
const action = ['ditch', 'drop', 'forget', 'throw out', 'leave', 'set down', 'let go of'];
|
||||
const getActions = ['pick up', 'grab', 'get', 'aquire', 'obtain', 'gain', 'take possesssion of'];
|
||||
|
||||
module.exports = {
|
||||
name: "inventory",
|
||||
@@ -235,67 +235,6 @@ module.exports = {
|
||||
|
||||
interaction.send({ components: [opt], flags: (1 << 6) })
|
||||
|
||||
client.on("interactionCreate", MenuInteraction => {
|
||||
if(!MenuInteraction.isSelectMenu()) return;
|
||||
if (!MenuInteraction.customId.endsWith(MenuInteraction.member.user.id)) {
|
||||
return MenuInteraction.reply({
|
||||
content: "This button is not for you",
|
||||
flags: (1 << 6)
|
||||
})
|
||||
}
|
||||
|
||||
if (MenuInteraction.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 MenuInteraction.update({ embeds: [inventoryEmbed], components: [], flags: (1 << 6) });
|
||||
} else {
|
||||
let item = inventory.guilds[GuildDB.serverID].items[MenuInteraction.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 MenuInteraction.update({ embeds: [itemEmbed], components: [], flags: (1 << 6) });
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} else if (args[0].name == 'wallet') {
|
||||
// Display wallet
|
||||
|
||||
@@ -336,7 +275,7 @@ module.exports = {
|
||||
});
|
||||
|
||||
let message = new EmbedBuilder()
|
||||
.setTitle(`You ${actions[Math.floor(Math.random() * actions.length)]} a ${firearm.weaponType}`)
|
||||
.setTitle(`You ${getActions[Math.floor(Math.random() * actions.length)]} a ${firearm.weaponType}`)
|
||||
.setColor(client.config.Colors.Default);
|
||||
|
||||
return interaction.send({ embeds: [message] });
|
||||
@@ -371,41 +310,38 @@ module.exports = {
|
||||
|
||||
} 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] });
|
||||
}
|
||||
|
||||
if (args[0].options[0].value < 1 || args[0].options[0].value > inventory.guilds[GuildDB.serverID].items.length) {
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle("Please provide a valid item number")
|
||||
.setColor(client.config.Colors.Red)
|
||||
let items = new SelectMenuBuilder()
|
||||
.setCustomId(`dropSelect-${interaction.member.user.id}`)
|
||||
.setPlaceholder('Select item to drop')
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
|
||||
if (args[0].options[0].value == 1) {
|
||||
let embed = new EmbedBuilder()
|
||||
.setTitle("Cannot Drop Wallet")
|
||||
.setColor(client.config.Colors.Default);
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
|
||||
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) {
|
||||
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.send({ embeds: [embed] });
|
||||
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);
|
||||
|
||||
let message = new EmbedBuilder()
|
||||
.setTitle(`You ${action[Math.floor(Math.random() * actions.length)]} your ${item.name}`)
|
||||
.setColor(client.config.Colors.Default);
|
||||
|
||||
return interaction.send({ embeds: [message] });
|
||||
});
|
||||
interaction.send({ components: [opt], flags: (1 << 6) })
|
||||
|
||||
} else if (args[0].name == 'give') {
|
||||
if (inventory.guilds[GuildDB.serverID].items.length == 1) {
|
||||
@@ -416,28 +352,23 @@ module.exports = {
|
||||
return interaction.send({ embeds: [nsi] });
|
||||
}
|
||||
|
||||
const targetUserID = args[0].options[0].value.replace('<@!', '').replace('>', '');
|
||||
|
||||
let items = new SelectMenuBuilder()
|
||||
.setCustomId(`inventorySelect-${interaction.member.user.id}`)
|
||||
.setPlaceholder('Select Item to view')
|
||||
.addOptions(
|
||||
{
|
||||
label: 'View All',
|
||||
description: 'View a list of all your inventory items',
|
||||
value: 'all',
|
||||
}
|
||||
)
|
||||
.setCustomId(`giveSelect-${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: 'View this items description',
|
||||
description: 'Give this item',
|
||||
value: `${i}`
|
||||
})
|
||||
} else {
|
||||
items.addOptions({
|
||||
label: inventory.guilds[GuildDB.serverID].items[i].name,
|
||||
description: 'View this items description',
|
||||
description: 'Give this item',
|
||||
value: `${i}`
|
||||
})
|
||||
}
|
||||
@@ -446,79 +377,6 @@ module.exports = {
|
||||
const opt = new ActionRowBuilder().addComponents(items);
|
||||
|
||||
interaction.send({ components: [opt], flags: (1 << 6) })
|
||||
|
||||
client.on("interactionCreate", MenuInteraction => {
|
||||
if(!MenuInteraction.isSelectMenu()) return;
|
||||
if (!MenuInteraction.customId.endsWith(MenuInteraction.member.user.id)) {
|
||||
return MenuInteraction.reply({
|
||||
content: "This button is not for you",
|
||||
flags: (1 << 6)
|
||||
})
|
||||
}
|
||||
|
||||
let item = inventory.guilds[GuildDB.serverID].items[MenuInteraction.values[0]];
|
||||
let targetUserID = args[0].options[1].value.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) {
|
||||
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 MenuInteraction.update({ embeds: [embed], components: [] });
|
||||
}
|
||||
});
|
||||
} else {
|
||||
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 MenuInteraction.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) {
|
||||
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 MenuInteraction.update({ embeds: [embed], components: [] });
|
||||
}
|
||||
});
|
||||
client.dbo.collection('inventories').updateOne({'inventory.userID': targetUserID}, {$push: {[`inventory.guilds.${GuildDB.serverID}.items`]: item}}, function(err, res) {
|
||||
if (err) {
|
||||
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 MenuInteraction.update({ embeds: [embed], components: [] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let successEmbed = new EmbedBuilder()
|
||||
.setTitle('Success')
|
||||
.setDescription(`Successfully gave <@${targetUserID}> ${item.name}`)
|
||||
.setColor('GREEN');
|
||||
|
||||
return MenuInteraction.update({ embeds: [successEmbed], components: [] });
|
||||
});
|
||||
|
||||
|
||||
} else if (args[0].name == 'clear') {
|
||||
const prompt = new EmbedBuilder()
|
||||
@@ -529,48 +387,16 @@ module.exports = {
|
||||
const opt = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`yes-${interaction.member.user.id}`)
|
||||
.setCustomId(`inventoryClear-yes-${interaction.member.user.id}`)
|
||||
.setLabel("Yes")
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`no-${interaction.member.user.id}`)
|
||||
.setCustomId(`inventoryClear-no-${interaction.member.user.id}`)
|
||||
.setLabel("No")
|
||||
.setStyle(ButtonStyle.Success)
|
||||
)
|
||||
|
||||
interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
|
||||
|
||||
client.on("interactionCreate", ButtonInteraction => {
|
||||
if(!ButtonInteraction.isButton()) return;
|
||||
const queryString = ButtonInteraction.customId;
|
||||
if (!queryString.endsWith(ButtonInteraction.member.user.id)) {
|
||||
return ButtonInteraction.reply({
|
||||
content: "This button is not for you",
|
||||
flags: (1 << 6)
|
||||
})
|
||||
}
|
||||
let action = ''
|
||||
if (queryString==`yes-${interaction.member.user.id}`) {
|
||||
action = 'cleared';
|
||||
const tempWallet = inventory.guilds[GuildDB.serverID].items[0];
|
||||
client.dbo.collection("inventories").updateOne({"inventory.userID":inventory.userID},{$set:{[`inventory.guilds.${GuildDB.serverID}.items`]: [tempWallet]}},function(err, res) {
|
||||
if (err) {
|
||||
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.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
} else if (queryString==`no-${interaction.member.user.id}`) action = 'kept';
|
||||
|
||||
const successEmbed = new EmbedBuilder()
|
||||
.setColor(client.config.Colors.Green)
|
||||
.setTitle(`Successfully ${action} your inventory.`)
|
||||
|
||||
return ButtonInteraction.update({ embeds: [successEmbed], components: [] });
|
||||
});
|
||||
return interaction.send({ embeds: [prompt], components: [opt], flags: (1 << 6) });
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user