Add list-orphans command
This commit is contained in:
parent
5f6cb95f52
commit
3bea94bee0
|
@ -296,6 +296,11 @@ module.exports = [
|
|||
"required": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "list-orphans",
|
||||
"description": "List all orphaned extensions (extensions without a Discord user linked)",
|
||||
"type": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue