45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
const client = global.discord_client
|
|
const pool = global.db_pool;
|
|
|
|
const execute = async (interaction) => {
|
|
if (!interaction.guildId) return interaction.reply({ content: "This command can only be used in a server", ephemeral: true });
|
|
var robloxID = interaction.options.getNumber("roblox-id") || null;
|
|
const discordID = interaction.options.getUser("discord-id")?.id || null;
|
|
if (!robloxID && !discordID) return interaction.reply({ content: "You must provide a Roblox ID or Discord ID", ephemeral: true });
|
|
|
|
// If both robloxID and discordID are provided, we can't continue
|
|
if (robloxID && discordID) return interaction.reply({ content: "You can't provide both a Roblox ID and Discord ID", ephemeral: true });
|
|
|
|
// If discordID is provided, we need to find the robloxID
|
|
if (discordID) {
|
|
const [user] = await pool.query('SELECT * FROM users WHERE discordId = ?', [discordID]);
|
|
if (!user) return interaction.reply({ content: "User not found", ephemeral: true });
|
|
robloxID = user.robloxId;
|
|
}
|
|
|
|
// Check if the user exists
|
|
const [user] = await pool.query('SELECT * FROM users WHERE robloxId = ?', [robloxID]);
|
|
if (!user) return interaction.reply({ content: "User not found", ephemeral: true });
|
|
|
|
// Check if the user already owns the product
|
|
const purchases = await pool.query('SELECT * FROM purchases WHERE robloxId = ?', [robloxID]);
|
|
const products = await pool.query('SELECT * FROM products');
|
|
|
|
const embed = {
|
|
title: `Profile for ${user.discordDisplayName}`,
|
|
description: `Roblox ID: ${robloxID}`,
|
|
fields: [
|
|
{
|
|
name: `Owned Products (${purchases.length})`,
|
|
value: purchases.map(purchase => {
|
|
const product = products.find(product => product.id === purchase.productId);
|
|
return product.name;
|
|
}).join("\n")
|
|
}
|
|
]
|
|
}
|
|
|
|
return interaction.reply({ embeds: [embed] });
|
|
};
|
|
|
|
module.exports = { execute }
|