2022-10-26 12:38:28 +02:00
|
|
|
const { EmbedBuilder } = require("discord.js");
|
2021-06-12 12:53:51 +02:00
|
|
|
const inv = require("../../models/econ");
|
2021-11-18 18:56:42 +01:00
|
|
|
const { Pagination } = require("cath");
|
|
|
|
const items = require("../../util/Data/item.json");
|
2021-06-12 12:53:51 +02:00
|
|
|
module.exports = {
|
|
|
|
name: "inventory",
|
|
|
|
description: "Check the inventory of an user",
|
|
|
|
usage: "{User}",
|
|
|
|
category: "Economy",
|
|
|
|
timeout: 5000,
|
2021-09-17 18:28:39 +02:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
type: 6,
|
|
|
|
name: "user",
|
|
|
|
description: "The user you want to see",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
],
|
2021-11-18 18:56:42 +01:00
|
|
|
run: async (client, interaction, args) => {
|
|
|
|
const util = new Pagination();
|
2021-06-12 12:53:51 +02:00
|
|
|
const user =
|
2021-09-17 18:28:39 +02:00
|
|
|
interaction.guild.members.cache.get(args[0]) || interaction.member;
|
2021-06-12 12:53:51 +02:00
|
|
|
inv.findOne({ User: user.id }, async (err, data) => {
|
2021-07-13 05:17:39 +02:00
|
|
|
if (data) {
|
2021-11-18 18:56:42 +01:00
|
|
|
if (!data.Inventory) {
|
2021-09-17 18:28:39 +02:00
|
|
|
return interaction.followUp({
|
|
|
|
content: `User doesn't have any data`,
|
|
|
|
});
|
2021-11-18 18:56:42 +01:00
|
|
|
}
|
|
|
|
const mappedData = Object.keys(data.Inventory)
|
|
|
|
.map(key => {
|
|
|
|
if (data.Inventory[key] == 0) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
const name = items.find(val => val.dbname === key).name;
|
|
|
|
const emoji = items.find(val => val.dbname === key).emoji;
|
|
|
|
const type = items.find(val => val.dbname === key).type;
|
|
|
|
return `\n**${emoji}${name}** — ${data.Inventory[key]}\n **Type**: \`${type}\``;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter(e => e !== undefined);
|
2021-07-13 05:17:39 +02:00
|
|
|
if (mappedData.length == 0) {
|
2021-09-17 18:28:39 +02:00
|
|
|
return interaction.followUp({
|
|
|
|
content: `User doesn't have any data`,
|
|
|
|
});
|
2021-07-13 05:17:39 +02:00
|
|
|
}
|
|
|
|
const c = util.chunk(mappedData, 5).map(x => x.join("\n"));
|
2022-10-26 12:38:28 +02:00
|
|
|
const embed = new EmbedBuilder()
|
2021-07-13 05:17:39 +02:00
|
|
|
.setTimestamp()
|
|
|
|
.setTitle(`${user.displayName}'s inventory`)
|
2021-09-17 18:28:39 +02:00
|
|
|
.setColor(client.color)
|
2021-07-13 05:17:39 +02:00
|
|
|
.setDescription(c[0])
|
2022-10-26 12:38:28 +02:00
|
|
|
.setFooter({ text: `Page 1 of ${c.length}` });
|
2021-07-13 05:17:39 +02:00
|
|
|
try {
|
2021-09-17 18:28:39 +02:00
|
|
|
const msg = await interaction.followUp({ embeds: [embed] });
|
2021-11-18 18:56:42 +01:00
|
|
|
if (mappedData.length > 5) {
|
2021-09-17 18:28:39 +02:00
|
|
|
await util.pagination(msg, interaction.user, c);
|
2021-11-18 18:56:42 +01:00
|
|
|
}
|
2021-07-13 05:17:39 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
2021-11-18 18:56:42 +01:00
|
|
|
} else {
|
2021-09-17 18:28:39 +02:00
|
|
|
return interaction.followUp({ content: `User doesn't have any data` });
|
2021-11-18 18:56:42 +01:00
|
|
|
}
|
2021-06-12 12:53:51 +02:00
|
|
|
});
|
2021-09-17 18:28:39 +02:00
|
|
|
},
|
|
|
|
};
|