From dba95171c84ab1d5209192b41ecb73ab0a76034c Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 15 Sep 2025 06:33:16 -0600 Subject: [PATCH] Use msg editing brr --- messageHandlers/hub_settings.js | 140 ++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 62 deletions(-) diff --git a/messageHandlers/hub_settings.js b/messageHandlers/hub_settings.js index ea54aa1..eed9a9b 100644 --- a/messageHandlers/hub_settings.js +++ b/messageHandlers/hub_settings.js @@ -35,36 +35,50 @@ const cancel = (user) => { } const opts = { // Map of option number to step number - 1: {step: 21, exec: (hubId, uid) => { - return 'Please provide the new short description. Say `cancel` to exit.'; - }}, - 2: {step: 22, exec: (hubId, uid) => { - return 'Please provide the new long description. Say `cancel` to exit.'; - }}, - 3: {step: 1, exec: async (hubId, uid) => { - const [hub] = await pool.query('SELECT allowGiftPurchase FROM hubs WHERE id = ?', [hubId]); - if (!hub) return 'Error fetching hub data.'; - const newValue = hub.allowGiftPurchase ? 0 : 1; - await pool.query('UPDATE hubs SET allowGiftPurchase = ? WHERE id = ?', [newValue, hubId]); - return `Allow Gift Purchase is now set to: ${newValue ? "Yes" : "No"}.\n\nType another option number, or \`cancel\` to exit.`; - }}, - 4: {step: 24, exec: (hubId, uid) => { - return 'Please provide the new Terms of Service. Say `cancel` to exit.'; - }}, - 5: {step: 25, exec: async (hubId, uid) => { - const newKey = crypto.randomBytes(16).toString('hex'); - await pool.query('UPDATE hubs SET secretKey = ? WHERE id = ?', [newKey, hubId]); - return `New secret key generated: ||${newKey}||\n\nType another option number, or \`cancel\` to exit.`; - }}, - 6: {step: 1, exec: (hubId, uid) => { - return 'Parcel Auto-Import setup is not yet implemented. Type another option number, or `cancel` to exit.'; - }}, - 7: {step: 27, exec: async (hubId, uid) => { - // generate a random confirmation code - const confirmationCode = crypto.randomBytes(8).toString('hex'); - global.hubSettingsHandlers[uid].confirmationCode = confirmationCode; - return `***__WARNING: THIS WILL DELETE THE HUB AND ALL PRODUCTS! THIS ACTION CANNOT BE UNDONE.__***\nTo confirm deletion, please type the following: \`confirm ${confirmationCode}\`. Type \`cancel\` to exit.`; - }} + 1: { + step: 21, exec: (hubId, uid) => { + return 'Please provide the new short description. Say `cancel` to exit.'; + } + }, + 2: { + step: 22, exec: (hubId, uid) => { + return 'Please provide the new long description. Say `cancel` to exit.'; + } + }, + 3: { + step: 1, exec: async (hubId, uid) => { + const [hub] = await pool.query('SELECT allowGiftPurchase FROM hubs WHERE id = ?', [hubId]); + if (!hub) return 'Error fetching hub data.'; + const newValue = hub.allowGiftPurchase ? 0 : 1; + await pool.query('UPDATE hubs SET allowGiftPurchase = ? WHERE id = ?', [newValue, hubId]); + return `Allow Gift Purchase is now set to: ${newValue ? "Yes" : "No"}.\n\nType another option number, or \`cancel\` to exit.`; + } + }, + 4: { + step: 24, exec: (hubId, uid) => { + return 'Please provide the new Terms of Service. Say `cancel` to exit.'; + } + }, + 5: { + step: 25, exec: async (hubId, uid) => { + const newKey = crypto.randomBytes(16).toString('hex'); + await pool.query('UPDATE hubs SET secretKey = ? WHERE id = ?', [newKey, hubId]); + return `New secret key generated: ||${newKey}||\n\nType another option number, or \`cancel\` to exit.`; + } + }, + 6: { + step: 1, exec: (hubId, uid) => { + return 'Parcel Auto-Import setup is not yet implemented. Type another option number, or `cancel` to exit.'; + } + }, + 7: { + step: 27, exec: async (hubId, uid) => { + // generate a random confirmation code + const confirmationCode = crypto.randomBytes(8).toString('hex'); + global.hubSettingsHandlers[uid].confirmationCode = confirmationCode; + return `***__WARNING: THIS WILL DELETE THE HUB AND ALL PRODUCTS! THIS ACTION CANNOT BE UNDONE.__***\nTo confirm deletion, please type the following: \`confirm ${confirmationCode}\`. Type \`cancel\` to exit.`; + } + } } const execute = async (message) => { @@ -135,38 +149,40 @@ const execute = async (message) => { message.channel.send('Invalid confirmation code. Please type the exact confirmation code sent to you, or `cancel` to exit.'); return; } - // Proceed with deletion - const hubId = global.hubSettingsHandlers[message.author.id].hub; - // Delete fileAuth - message.channel.send("Deleting file authorizations..."); - await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); - // Delete files - message.channel.send("Deleting product files..."); - // const safeFileId = path.basename(product.file); - // const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route - const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]); - for (const fileRow of files) { - const safeFileId = path.basename(fileRow.file); - const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route - if (fs.existsSync(filePath)) { - fs.unlinkSync(filePath); - message.channel.send(`Deleted file: ${safeFileId}`); - } else { - message.channel.send(`File not found, skipping: ${safeFileId}`); + message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => { + // Proceed with deletion + const hubId = global.hubSettingsHandlers[message.author.id].hub; + // Delete fileAuth + msg.edit(msg.content + '\nDeleting file authorizations...'); + await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); + // Delete files + msg.edit(msg.content + '\nDeleting product files...'); + // const safeFileId = path.basename(product.file); + // const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route + const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]); + for (const fileRow of files) { + const safeFileId = path.basename(fileRow.file); + const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route + if (fs.existsSync(filePath)) { + fs.unlinkSync(filePath); + msg.edit(msg.content + `\nDeleted file: ${safeFileId}`); + } else { + msg.edit(msg.content + `\nFile not found, skipping: ${safeFileId}`); + } } - } - - // Delete purchases - message.channel.send("Deleting purchases..."); - await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); - // Delete products - message.channel.send("Deleting products..."); - await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]); - // Delete hub - message.channel.send("Deleting hub..."); - await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]); - message.channel.send('Hub has been deleted. Exiting settings. Thank you!'); - cancel(message.author); + + // Delete purchases + msg.edit(msg.content + '\nDeleting purchases...'); + await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); + // Delete products + msg.edit(msg.content + '\nDeleting products...'); + await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]); + // Delete hub + msg.edit(msg.content + '\nDeleting hub...'); + await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]); + msg.edit(msg.content + '\nDeletion process complete.'); + cancel(message.author); + }); break; default: message.channel.send('Invalid step.'); @@ -175,4 +191,4 @@ const execute = async (message) => { break; } } - module.exports = execute \ No newline at end of file +module.exports = execute \ No newline at end of file