Add list-orphans command
This commit is contained in:
parent
5f6cb95f52
commit
3bea94bee0
|
@ -296,6 +296,11 @@ module.exports = [
|
||||||
"required": true
|
"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 pool.query('DELETE FROM discord_users WHERE extension = ?', [ext]);
|
||||||
await interaction.editReply({ content: `Extension ${ext} unlinked from ${lookup.discordId}!`, ephemeral: true });
|
await interaction.editReply({ content: `Extension ${ext} unlinked from ${lookup.discordId}!`, ephemeral: true });
|
||||||
break;
|
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:
|
default:
|
||||||
await interaction.reply({ content: 'Unknown subcommand!', ephemeral: true });
|
await interaction.reply({ content: 'Unknown subcommand!', ephemeral: true });
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue