const pool = global.pool const fpbx = global.fpbx const client = global.client const log = global.log module.exports = {}; module.exports.execute = async (interaction) => { const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]); if (!lookup) { await interaction.reply({ content: `We're sorry, It doesn't look like you have an extension!`, ephemeral: true }); return; } await interaction.deferReply({ ephemeral: true }); console.log(JSON.stringify(interaction, null, 2)); let passwordToSet = newPassword; if (!newPassword || newPassword.trim() === '') { // Generate password based on process.env.PASSWORD_LENGTH and process.env.PASSWORD_CHARS or default to 32 alphanumeric with caps const length = parseInt(process.env.PASSWORD_LENGTH) || 32; const chars = process.env.PASSWORD_CHARS || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; passwordToSet = Array.from({ length }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join(''); } try { await fpbx.updateExtPassword(lookup.extension, passwordToSet); await interaction.editReply({ content: `Your extension password has been reset successfully! Your new password is: ||\`${passwordToSet}\`||`, ephemeral: true }); } catch (error) { log.error(error); await interaction.editReply({ content: 'There was an error while resetting your extension password!', ephemeral: true }); } }