const client = global.discord_client const pool = global.db_pool; const execute = async (interaction) => { 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 [row] = await pool.query('SELECT * FROM users WHERE discordId = ?', [discordID]); if (!row) return interaction.reply({ content: "User not found", ephemeral: true }); robloxID = row.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 }); const productName = interaction.options.getString("product-name"); // try catch try and find the product based on partial product name, parse everything in uppercase to make things easier const [product] = await pool.query('SELECT * FROM products WHERE UPPER(name) LIKE ?', [`%${productName.toUpperCase()}%`]); if (!product) return interaction.reply({ content: "Product not found", ephemeral: true }); // Check if the user already owns the product const [purchase] = await pool.query('SELECT * FROM purchases WHERE robloxId = ? AND productId = ?', [robloxID, product.id]); if (purchase) return interaction.reply({ content: "User already owns this product", ephemeral: true }); // Insert purchase into database await pool.query('INSERT INTO purchases (robloxId, productId, hubId) VALUES (?, ?, ?)', [robloxID, product.id, product.hubId]); return interaction.reply({ content: `Gave \`${product.name}\` to ${robloxID}`, ephemeral: true }); }; module.exports = { execute }