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; } // Get the hub for the guild const guildID = interaction.guild.id; const [hub] = await pool.query('SELECT * FROM hubs WHERE discordGuild = ?', [guildID]); if (!hub) return interaction.reply({ content: "Hub not found for this guild", ephemeral: true }); // 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 ? AND hubId = ?', [`%${productName.toUpperCase()}%`, hub.id]); 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]); try { // Assuming you have a function to send a message to the user dscUser = await client.users.fetch(user.discordId); dscUser.send(`You have been givena copy of ${product.name}!\nUse \`/retrive ${product.name}\` in the Discord server to download it!`); } catch (error) { // Do nothing, user has privacy settings enabled } if (hub.logChannel != null) { try { chan = await client.channels.fetch(hub.logChannel); chan.send({ embeds: [ { title: `Product Given`, color: 0x00ff00, description: `**Roblox ID:** ${user.robloxId}\n**Discord User:** <@${user.discordId}>\n**Product:** ${product.name}\n**Type:** Give` } ] }) } catch (error) { // Do nothing, channel was deleted } } return interaction.reply({ content: `Gave \`${product.name}\` to ${robloxID}`, ephemeral: true }); }; module.exports = { execute }