Use msg editing brr

This commit is contained in:
Christopher Cookman 2025-09-15 06:33:16 -06:00
parent e52c93da5d
commit dba95171c8

View file

@ -35,36 +35,50 @@ const cancel = (user) => {
} }
const opts = { // Map of option number to step number const opts = { // Map of option number to step number
1: {step: 21, exec: (hubId, uid) => { 1: {
return 'Please provide the new short description. Say `cancel` to exit.'; 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.'; },
}}, 2: {
3: {step: 1, exec: async (hubId, uid) => { step: 22, exec: (hubId, uid) => {
const [hub] = await pool.query('SELECT allowGiftPurchase FROM hubs WHERE id = ?', [hubId]); return 'Please provide the new long description. Say `cancel` to exit.';
if (!hub) return 'Error fetching hub data.'; }
const newValue = hub.allowGiftPurchase ? 0 : 1; },
await pool.query('UPDATE hubs SET allowGiftPurchase = ? WHERE id = ?', [newValue, hubId]); 3: {
return `Allow Gift Purchase is now set to: ${newValue ? "Yes" : "No"}.\n\nType another option number, or \`cancel\` to exit.`; step: 1, exec: async (hubId, uid) => {
}}, const [hub] = await pool.query('SELECT allowGiftPurchase FROM hubs WHERE id = ?', [hubId]);
4: {step: 24, exec: (hubId, uid) => { if (!hub) return 'Error fetching hub data.';
return 'Please provide the new Terms of Service. Say `cancel` to exit.'; const newValue = hub.allowGiftPurchase ? 0 : 1;
}}, await pool.query('UPDATE hubs SET allowGiftPurchase = ? WHERE id = ?', [newValue, hubId]);
5: {step: 25, exec: async (hubId, uid) => { return `Allow Gift Purchase is now set to: ${newValue ? "Yes" : "No"}.\n\nType another option number, or \`cancel\` to exit.`;
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.`; 4: {
}}, step: 24, exec: (hubId, uid) => {
6: {step: 1, exec: (hubId, uid) => { return 'Please provide the new Terms of Service. Say `cancel` to exit.';
return 'Parcel Auto-Import setup is not yet implemented. Type another option number, or `cancel` to exit.'; }
}}, },
7: {step: 27, exec: async (hubId, uid) => { 5: {
// generate a random confirmation code step: 25, exec: async (hubId, uid) => {
const confirmationCode = crypto.randomBytes(8).toString('hex'); const newKey = crypto.randomBytes(16).toString('hex');
global.hubSettingsHandlers[uid].confirmationCode = confirmationCode; await pool.query('UPDATE hubs SET secretKey = ? WHERE id = ?', [newKey, hubId]);
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.`; 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) => { 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.'); message.channel.send('Invalid confirmation code. Please type the exact confirmation code sent to you, or `cancel` to exit.');
return; return;
} }
// Proceed with deletion message.channel.send('Deletion Confirmed. Starting deletion process...').then(async msg => {
const hubId = global.hubSettingsHandlers[message.author.id].hub; // Proceed with deletion
// Delete fileAuth const hubId = global.hubSettingsHandlers[message.author.id].hub;
message.channel.send("Deleting file authorizations..."); // Delete fileAuth
await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); msg.edit(msg.content + '\nDeleting file authorizations...');
// Delete files await pool.query('DELETE FROM fileAuth WHERE product IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
message.channel.send("Deleting product files..."); // Delete files
// const safeFileId = path.basename(product.file); msg.edit(msg.content + '\nDeleting product files...');
// const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route // const safeFileId = path.basename(product.file);
const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]); // const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
for (const fileRow of files) { const files = await pool.query('SELECT file FROM products WHERE hubId = ?', [hubId]);
const safeFileId = path.basename(fileRow.file); for (const fileRow of files) {
const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route const safeFileId = path.basename(fileRow.file);
if (fs.existsSync(filePath)) { const filePath = path.join(__dirname, '../productFiles', safeFileId); // Code we use in the CDN route
fs.unlinkSync(filePath); if (fs.existsSync(filePath)) {
message.channel.send(`Deleted file: ${safeFileId}`); fs.unlinkSync(filePath);
} else { msg.edit(msg.content + `\nDeleted file: ${safeFileId}`);
message.channel.send(`File not found, skipping: ${safeFileId}`); } else {
msg.edit(msg.content + `\nFile not found, skipping: ${safeFileId}`);
}
} }
}
// Delete purchases // Delete purchases
message.channel.send("Deleting purchases..."); msg.edit(msg.content + '\nDeleting purchases...');
await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]); await pool.query('DELETE FROM purchases WHERE productId IN (SELECT id FROM products WHERE hubId = ?)', [hubId]);
// Delete products // Delete products
message.channel.send("Deleting products..."); msg.edit(msg.content + '\nDeleting products...');
await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]); await pool.query('DELETE FROM products WHERE hubId = ?', [hubId]);
// Delete hub // Delete hub
message.channel.send("Deleting hub..."); msg.edit(msg.content + '\nDeleting hub...');
await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]); await pool.query('DELETE FROM hubs WHERE id = ?', [hubId]);
message.channel.send('Hub has been deleted. Exiting settings. Thank you!'); msg.edit(msg.content + '\nDeletion process complete.');
cancel(message.author); cancel(message.author);
});
break; break;
default: default:
message.channel.send('Invalid step.'); message.channel.send('Invalid step.');
@ -175,4 +191,4 @@ const execute = async (message) => {
break; break;
} }
} }
module.exports = execute module.exports = execute