diff --git a/commands.js b/commands.js index 15060e6..605780f 100644 --- a/commands.js +++ b/commands.js @@ -296,6 +296,11 @@ module.exports = [ "required": true } ] + }, + { + "name": "list-orphans", + "description": "List all orphaned extensions (extensions without a Discord user linked)", + "type": 1 } ] } diff --git a/interactionHandlers/commands/manage.js b/interactionHandlers/commands/manage.js index c200a2e..a6a95a5 100644 --- a/interactionHandlers/commands/manage.js +++ b/interactionHandlers/commands/manage.js @@ -120,6 +120,20 @@ module.exports.execute = async (interaction) => { await pool.query('DELETE FROM discord_users WHERE extension = ?', [ext]); await interaction.editReply({ content: `Extension ${ext} unlinked from ${lookup.discordId}!`, ephemeral: true }); break; + case "list-orphans": // List all orphaned extensions (extensions without a Discord user linked) + await interaction.deferReply({ ephemeral: true }); + const [orphans] = await pool.query('SELECT id,description FROM asterisk.devices WHERE id NOT IN (SELECT extension FROM asterisk.discord_users)'); + if (orphans.length === 0) { + await interaction.editReply({ content: 'No orphaned extensions found!', ephemeral: true }); + return; + } + const orphanList = orphans.map(o => `**Extension:** \`${o.id}\` - **Name:** \`${o.description}\``).join('\n'); + await interaction.editReply({ + content: `**Orphaned Extensions:**\n${orphanList}`, + ephemeral: true + }); + break; + default: await interaction.reply({ content: 'Unknown subcommand!', ephemeral: true }); break;