diff --git a/messageHandlers/hub_settings.js b/messageHandlers/hub_settings.js index eed9a9b..5ee4f54 100644 --- a/messageHandlers/hub_settings.js +++ b/messageHandlers/hub_settings.js @@ -150,13 +150,16 @@ const execute = async (message) => { return; } message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => { + curMsg = msg.content; // Proceed with deletion const hubId = global.hubSettingsHandlers[message.author.id].hub; // Delete fileAuth - msg.edit(msg.content + '\nDeleting file authorizations...'); + curMsg = curMsg + '\nDeleting file authorizations...' + await msg.edit(curMsg); 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...'); + curMsg = curMsg + '\nDeleting product files...' + await msg.edit(curMsg); // 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]); @@ -165,22 +168,28 @@ const execute = async (message) => { 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}`); + curMsg = curMsg + `\nDeleted file: ${safeFileId}`; + await msg.edit(curMsg); } else { - msg.edit(msg.content + `\nFile not found, skipping: ${safeFileId}`); + curMsg = curMsg + `\nFile not found (skipping): ${safeFileId}`; + await msg.edit(curMsg); } } // Delete purchases - msg.edit(msg.content + '\nDeleting purchases...'); + curMsg = curMsg + '\nDeleting purchases...'; + await msg.edit(curMsg); await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); // Delete products - msg.edit(msg.content + '\nDeleting products...'); + curMsg = curMsg + '\nDeleting products...'; + await msg.edit(curMsg); await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]); // Delete hub - msg.edit(msg.content + '\nDeleting hub...'); + curMsg = curMsg + '\nDeleting hub...'; + await msg.edit(curMsg); await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]); - msg.edit(msg.content + '\nDeletion process complete.'); + curMsg = curMsg + '\nHub and all associated data deleted successfully.'; + await msg.edit(curMsg); cancel(message.author); }); break;