40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
const pool = global.pool
|
|
const fpbx = global.fpbx
|
|
const client = global.client
|
|
const log = global.log
|
|
|
|
module.exports = {};
|
|
|
|
module.exports.execute = async (interaction) => {
|
|
await interaction.deferReply({ ephemeral: true });
|
|
const [lookup] = await pool.query('SELECT * FROM discord_users WHERE discordId = ?', [interaction.user.id]);
|
|
if (lookup) {
|
|
await interaction.editReply({ content: `You already have an extension, it's ${lookup.extension}!`, ephemeral: true });
|
|
return;
|
|
}
|
|
await interaction.editReply({ content: `Finding available extension`, ephemeral: true });
|
|
fpbx.getNextAvailableExtension().then(async (nextExt) => {
|
|
await interaction.editReply({ content: `Found ${nextExt}. Creating..`, ephemeral: true });
|
|
fpbx.addExtension(nextExt, interaction.user.username).then(async (res) => {
|
|
if (res.addExtension.status != true) {
|
|
await interaction.editReply({ content: `Something went wrong :(`, ephemeral: true });
|
|
return;
|
|
}
|
|
await pool.query('INSERT INTO discord_users (discordId, extension) VALUES (?, ?)', [interaction.user.id, nextExt]);
|
|
await interaction.editReply({ content: `Extension ${nextExt} created! Getting info..`, ephemeral: true });
|
|
await fpbx.reload();
|
|
const extInfo = await fpbx.getExtension(nextExt);
|
|
await interaction.editReply({ embeds: [{
|
|
title: "Your Extension Info",
|
|
description: `**PBX Address:** \`${process.env.PBX_HOSTNAME}\`\n**Extension:** \`${extInfo.fetchExtension.user.extension}\`\n**Name:** \`${extInfo.fetchExtension.user.name}\`\n**Password:** ||\`${extInfo.fetchExtension.user.extPassword}\`||`,
|
|
color: 0x00ff00
|
|
}], ephemeral: true })
|
|
}).catch(async (error) => {
|
|
log.error(error);
|
|
await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true });
|
|
});
|
|
}).catch(async (error) => {
|
|
log.error(error);
|
|
await interaction.editReply({ content: 'There was an error while creating your extension!', ephemeral: true });
|
|
});
|
|
} |