nyx/unused/commands/Economy/shop.js

79 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-10-26 12:38:28 +02:00
const { EmbedBuilder } = require("discord.js");
const { Pagination } = require("cath");
const items = require("../../util/Data/item.json");
2021-06-12 12:53:51 +02:00
module.exports = {
name: "shop",
description: "Check the items from the shop",
category: "Economy",
options: [
{
type: 3,
name: "item",
description: "The item you want to see",
required: false,
},
],
run: async (client, interaction, args, utils, data) => {
if (!args[0]) {
const util = new Pagination();
const list = items.map(value => {
return `**${value.emoji} ${
value.name
} [${value.price.toLocaleString()} ${
client.currency
}](https://www.youtube.com/watch?v=YSKDu1gKntY)**\n\`Aliases:\` **${value.aliases.join(
", "
)}**\n\`Type:\` **${value.type}**`;
});
const c = util.chunk(list, 5).map(x => x.join("\n\n"));
2022-10-26 12:38:28 +02:00
const embed = new EmbedBuilder()
.setTitle("**NYX Shop**")
.setTimestamp()
.setDescription(c[0])
.setColor(client.color)
2022-10-26 12:38:28 +02:00
.setFooter({ text: `Page 1 of ${c.length}` });
try {
const msg = await interaction.followUp({ embeds: [embed] });
if (list.length > 5) await util.pagination(msg, interaction.user, c);
} catch (e) {
console.log(e);
}
} else {
const itemToSearch = args[0].toLowerCase();
const validItem = !!items.find(item =>
item.aliases.includes(itemToSearch)
);
if (!validItem) {
interaction.followUp({
content:
"The item is not valid\nIf you want to get information about the item, use `/shop`",
});
} else {
const theitem = items.find(i => i.aliases.includes(itemToSearch));
2022-10-26 12:38:28 +02:00
const all = new EmbedBuilder()
.setTitle(`${theitem.emoji} ${theitem.name}`)
.setDescription(
`
**Owns** - ${
data.UserEcon.Inventory?.[theitem.dbname]
? data.UserEcon.Inventory?.[theitem.dbname]
: 0
}
**Cost Price** - ${client.currency} ${theitem.price}\n
**Sell Price** - ${client.currency} ${
theitem.sellable ? theitem.sell : "Unable to sell"
}\n
**Aliases** - \`${theitem.aliases.join(", ")}\`\n\n`
)
.setColor(client.color)
.setFooter(
`Made by ${client.author}`,
client.user.displayAvatarURL({ dynamic: true })
)
.setTimestamp();
interaction.followUp({ embeds: [all] });
}
2021-06-12 12:53:51 +02:00
}
},
};